c++若干重点整理(2)
2013-06-21 10:05
204 查看
CString取字符串长度:
总长:str.GetLength();
CString Left( int nCount ) const; //从左边1开始获取前 nCount 个字符
CString Mid( int nFirst ) const; //从左边第 nCount+1 个字符开始,获取后面所有的字符
CString Mid( int nFirst, int nCount ) const; //从左边第 nFirst+1 个字符开始,获取后面 nCount 个字符
CString Right( int nCount ) const; //从右边1开始获取从右向左前 nCount 个字符
voidMakeUpper(); //这个函数可以将CString字符转化为一个大写的字符串。
注:
在函数后面加 const 的意思是:
如果一个类声明了一个常量对象,这个对象只能使用后边带 const 这个的方法.
例:
CString a,b;
a = "123456789";
b = a.Left(4); //值为:1234
b = a.Mid(3); //值为:456789
b = a.Mid(2, 4); //值为:3456
b = a.Right(4); //值为:6789
The following example demonstrates the use of CString::MakeUpper.
// example for CString::MakeUpper
CString s( "abc" );
s.MakeUpper();
ASSERT( s == "ABC" );
在一个较大的字符串中查找字符或子字符串
int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR pstr, int nStart ) const;
返回此CString对象中与需要的子字符串或字符匹配的第一个字符的从零开始的索引;如果没有找到子字符串或字符则返回-1。
ch 要搜索的单个字符。
lpszSub 要搜索的子字符串。
nStart 字符串中开始搜索的字符的索引,如果是0,则是从头开始搜索。如果nStart不是0,则位于nStart之前的字符不包括在搜索之内。
pstr 指向要搜索的字符串的指针
/ CString::Find( TCHAR ch )
CString s( "abcdef" );
int n = s.Find( 'c' ); // 结果 n = 2
int f = s.Find( "de" ) ; // 结果 f = 3
总长:str.GetLength();
CString Left( int nCount ) const; //从左边1开始获取前 nCount 个字符
CString Mid( int nFirst ) const; //从左边第 nCount+1 个字符开始,获取后面所有的字符
CString Mid( int nFirst, int nCount ) const; //从左边第 nFirst+1 个字符开始,获取后面 nCount 个字符
CString Right( int nCount ) const; //从右边1开始获取从右向左前 nCount 个字符
voidMakeUpper(); //这个函数可以将CString字符转化为一个大写的字符串。
注:
在函数后面加 const 的意思是:
如果一个类声明了一个常量对象,这个对象只能使用后边带 const 这个的方法.
例:
CString a,b;
a = "123456789";
b = a.Left(4); //值为:1234
b = a.Mid(3); //值为:456789
b = a.Mid(2, 4); //值为:3456
b = a.Right(4); //值为:6789
The following example demonstrates the use of CString::MakeUpper.
// example for CString::MakeUpper
CString s( "abc" );
s.MakeUpper();
ASSERT( s == "ABC" );
在一个较大的字符串中查找字符或子字符串
int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR pstr, int nStart ) const;
返回值
返回此CString对象中与需要的子字符串或字符匹配的第一个字符的从零开始的索引;如果没有找到子字符串或字符则返回-1。
参数
ch 要搜索的单个字符。lpszSub 要搜索的子字符串。
nStart 字符串中开始搜索的字符的索引,如果是0,则是从头开始搜索。如果nStart不是0,则位于nStart之前的字符不包括在搜索之内。
pstr 指向要搜索的字符串的指针
/ CString::Find( TCHAR ch )
CString s( "abcdef" );
int n = s.Find( 'c' ); // 结果 n = 2
int f = s.Find( "de" ) ; // 结果 f = 3
相关文章推荐
- c++若干重点整理(1)
- javase复习整理(一):基础要点、重点、易错点、多线程梳理总结
- HTML5 Canvas 开发 绘图方法整理 【十三、Canvas重点之:状态 】
- 设计师整理的系统开发流程-简洁又有重点
- 金融法重点复习(整理)
- c语言面试题重点整理·单链表操作
- (整理) c++面向对象编程必备“良方”---重点难点总结
- C/C++经典面试50题(挑重点整理)
- 设计师整理的系统开发流程-简洁又有重点
- 整理的C语言指针重点
- tcp/ip协议详解及重点知识整理
- RxJava学习笔记整理重点
- 微服务Spring Cloud学习重点整理
- 整理C知识点--函数(重点)
- 【整理】Linq to Entity 动态拼接查询条件(重点是OR)
- Linux重点知识整理
- C Ch1重点整理-简介
- C++重点知识整理
- CNN的重点整理