C++常用数据结构-CString
CString类
Str.format(_T(“%d”),number)
例子: str.Format(_T("%d"),number);
%c 单个字符(char)
%d 十进制整数(int)
%ld 十进制整数(long)
%f 十进制浮点数(float)
%lf 十进制浮点数(double)
%o 八进制数
%s 字符串
%u 无符号十进制数
%x 十六进制数
%2f 输出两位数;包括小数点也算一位
%.2f 保留小数点后两位数
str.GetLength() 获取长度 字符个数
##########################################################################################
CString Left(int nCount) const;
从左取字串
例:csStr="abcdef";
cout<<csStr.Left(3); //abc
//当nCount等于0时,返回空。
//当nCount为负数时,返回空。
//当nCount大于对象长度时,返回值与对象相同。
##########################################################################################
CString Right( int nCount ) const;
从右取字串
例:csStr="abcdef";
; cout<<csStr.Right(3) //def
//当nCount等于0时,返回空。
//当nCount为负数时,返回空。
//当nCount大于对象长度时,返回值与对象相同。
##########################################################################################
CString Mid( int nFirst ) const;
CString Mid( int nFirst, int nCount ) const;
从中间开始取字串
例:csStr="abcdef";
cout<<csStr.Mid(2); //cdef
csStr="abcdef";
cout<<csStr.Mid(2,3); //cde
//当nFirst为0和为负数时,从第一个字符开始取。
//当nFirst等于对象末尾时,返回空字串。
//当nFirst超出对象末尾时,会发生无法预料的结果。
//当nCount超出对象末尾时,返回从nFirst开始一直到对象末尾的字串
//当nCount为0和为负数时,返回空字串。
##########################################################################################
int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR pstr, int nStart ) const;
查找字串,nStart为开始查找的位置。未找到匹配时返回-1,否则返回字串的开始位置
例:csStr="abcdef";
cout<<csStr.Find('b'); //1
cout<<csStr.Find("de"); //3
cout<<csStr.Find('b',3); //-1
cout<<csStr.Find('b',0); //1
cout<<csStr.Find("de",4); //-1
cout<<csStr.Find("de",0); //3
//当nStart超出对象末尾时,返回-1。
//当nStart为负数时,返回-1。
#########################################################################################
替换某个或者某几个字符
strTemp1.Replace(L"板子块数", L""); //将【板子块数】这四个字删掉
strTemp1.ReverseFind(_T("_")); //查找最后一个 _ 的位置,
strName.GetLength() //获取字符串长度
------------------------------------------------------------------------------------------
类型转换
int nIndex;
CString str;
1:字符串转整型:nEdge = _wtoi(strEdge);
2、整型转字符串:str.format("%d",nIndex);
3、字符串转浮点型
CString str="1.2";
float f;
f = atof(str);
4、字符串转整形
CString str = "123";
int i;
i = atoi(str);
5、CString 转 BSTR
CComBSTR MyBSTR = CComBSTR(fileName);
6、BSTR 转CString
CString str = CString(bstrName);
7、CComBSTR m_bstrCurPath
CString str = m_bstrCurPath.m_str
------------------------------------------------------------------------------------------
字符串数据拆分【SplitString】
bool CFoodSafety::SplitString(CString strCombo,CString strSeparator,vector<CString>& vecStrGroup)
{
vecStrGroup.clear();
if(strCombo.GetLength()==0)
{
return false;
}
while(1)
{
int nFind=strCombo.Find(strSeparator);
if(nFind==-1)//已经是最后一个串了
{
vecStrGroup.push_back(strCombo);
return true;
}
vecStrGroup.push_back(strCombo.Left(nFind));
int nLen=strCombo.GetLength();
strCombo=strCombo.Right(nLen-nFind-strSeparator.GetLength());
}
return true;
}
使用:
CString strName = _T("A_B_C_E_H");
vector<CString> vecInfo;
SplitString(strName,_T("_"),vecInfo); //拆分信息
访问:vecInfo[0] = _T("A");
vecInfo[1] = _T("B");
C++常用数据结构-CString的更多相关文章
- JAVA常用数据结构及原理分析
JAVA常用数据结构及原理分析 http://www.2cto.com/kf/201506/412305.html 前不久面试官让我说一下怎么理解java数据结构框架,之前也看过部分源码,balaba ...
- 常用数据结构及复杂度 array、LinkedList、List、Stack、Queue、Dictionary、SortedDictionary、HashSet、SortedSet
原文地址:http://www.cnblogs.com/gaochundong/p/data_structures_and_asymptotic_analysis.html 常用数据结构的时间复杂度 ...
- php常用数据结构
# 常用数据结构--------------------------------------------------------------------------------## 树(Tree)- ...
- Redis常用数据结构
Redis常用数据结构包括字符串(strings),列表(lists),哈希(hashes),集合(sets),有序集合(sorted sets). redis的key最大不能超过512M,可通过re ...
- Java 常用数据结构对象的实现原理 集合类 List Set Map 哪些线程安全 (美团面试题目)
Java中的集合包括三大类,它们是Set.List和Map, 它们都处于java.util包中,Set.List和Map都是接口,它们有各自的实现类. List.Set都继承自Collection接口 ...
- (6)Java数据结构-- 转:JAVA常用数据结构及原理分析
JAVA常用数据结构及原理分析 http://www.2cto.com/kf/201506/412305.html 前不久面试官让我说一下怎么理解java数据结构框架,之前也看过部分源码,balab ...
- 常用数据结构及算法C#/Java实现
常用数据结构及算法C#实现 1.冒泡排序.选择排序.插入排序(三种简单非递归排序) ,, , , , , , , , , }; //冒泡排序 int length = waitSort.Length; ...
- 图解Java常用数据结构(一)【转载】
最近在整理数据结构方面的知识, 系统化看了下Java中常用数据结构, 突发奇想用动画来绘制数据流转过程. 主要基于jdk8, 可能会有些特性与jdk7之前不相同, 例如LinkedList Linke ...
- 图解Java常用数据结构(一)
最近在整理数据结构方面的知识, 系统化看了下Java中常用数据结构, 突发奇想用动画来绘制数据流转过程. 主要基于jdk8, 可能会有些特性与jdk7之前不相同, 例如LinkedList Linke ...
随机推荐
- 解决 Unknown action buyram in contract eosio 错误
- chrome window 下的所有key josn
["postMessage","blur","focus","close","parent",&qu ...
- mysql数据库查询和聚合函数
1.模糊查询 like % 表示多个任意字符 _ 表示任意一个字符 例如:查询黄姓同学 select * from student where name '黄%' select * from stud ...
- mysql_索引
.默认情况下大多使用Btree索引,该索引就是通常所见 唯一索引.聚簇索引等等,Btree用在OLTP,加快查询速度 查询表索引 show index from tablename 查询表结构 ...
- linux 在后台常驻运行php脚本
php a.php &
- python 编写登陆接口
#!/usr/bin/env python#_*_ coding:utf-8 _*_dic={ 'yts':{'password':'123','count':0}, 'nick':{'passwor ...
- zoj 1649 bfs
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M ...
- C++实现简单学生管理系统
在网上看到的一个C++的小项目,我自己码了一遍,然后记录下我的理解以及像我这种菜鸟在整个过程中产生的问题. 我将我知道的尽可能详细的写下来,如有错误请联系我哈,QQ:920209178. 原文地址:h ...
- BBS
__init__.py # 这个告诉程序用的是什么数据库import pymysql pymysql.install_as_MySQLdb() settings.py import os # Buil ...
- django之Form组件补充
自定义验证规则 方法一: from django.forms import Form from django.forms import widgets from django.forms import ...