CString——Left、Right、Find、ReverseFind

来源:互联网 发布:手机怎样删除淘宝评价 编辑:程序博客网 时间:2024/05/16 09:26

转载来自:http://blog.sina.com.cn/s/blog_635ff3050102uyog.html

CString——Left、Right、Find、ReverseFind

 

CString::Left(intnCount)

——返回字符串前nCount个字符的字符串

example:

  CString str(_T("Shop,车间"));

  str = str.Left(4);

结果:str="Shop";

 

CString::Right(int nCount)

——返回字符串后nCount个字符的字符串

example:

  CString str(_T("Shop,车间"));

  str = str.Right(2);

结果:str="车间";

 

CString::Find(_T(","))

返回“,”在字符串中的索引值

example:

 CString str(_T("Shop,车间"));

  int idex = str.Find(_T(","));

此时:idex=4;

 

宗:要想获得“,”右侧内容

str = str.Right(str.GetLength()-1-str.Find(_T(",")));

其中:

str.GetLength()=7;

-1排除“,”

-str.Find(_T(","))排除“,”前的所有字

 

 

CString::ReverseFind

  int ReverseFind( TCHAR ch ) const;

  返回值:

  返回此CString对象中与要求的字符匹配的最后一个字符的索引;如果没有找到需要的字符则返回-1。

  参数: ch 要搜索的字符。

  说明:

  此成员函数在此CString对象中搜索与一个子串匹配的最后一个字符。此函数类似于运行时函数strrchr。

  示例:// CString::ReverseFind示例:

  CString s( "abcabc" );

  ASSERT( s.ReverseFind( 'b' ) == 4 );


0 0
原创粉丝点击