CString类常用方法----Left(),Mid(),Right()……

来源:互联网 发布:微信小程序系统源码 编辑:程序博客网 时间:2024/06/03 12:01
  1. CStringLeft(intnCount)const; //从左边1开始获取前 nCount个字符  
  2. CStringMid(intnFirst)const; //从左边第 nCount+1个字符开始,获取后面所有的字符  
  3. CStringMid(intnFirst,intnCount)const; //从左边第 nFirst+1 个字符开始,获取后面nCount个字符  
  4. CStringRight(intnCount)const; //从右边1开始获取从右向左前 nCount个字符  
  5.   
  6. voidMakeUpper(); //这个函数可以将CString字符转化为一个大写的字符串。  
  7.   
  8.   
  9. 注:  
  10. 在函数后面加 const 的意思是:  
  11. 如果一个类声明了一个常量对象,这个对象只能使用后边带 const 这个的方法.  
  12.   
  13. 例:  
  14. CString a,b;  
  15. a = "123456789";  
  16.   
  17. b =a.Left(4);  //值为:1234  
  18. b =a.Mid(3); //值为:456789  
  19. b = a.Mid(2, 4); //值为:3456  
  20. b = a.Right(4);  //值为:6789  
  21.   
  22. The following example demonstrates the useof CString::MakeUpper.  
  23. //example for CString::MakeUpper CStrings( "abc" ); s.MakeUpper(); ASSERT(s == "ABC" );  
  24.   
  25. 在一个较大的字符串中查找字符或子字符串  
  26. int Find( TCHAR ch ) const;  
  27. int Find( LPCTSTR lpszSub ) const;  
  28. intFind( TCHAR ch, int nStart ) const;intFind( LPCTSTR pstr, int nStart ) const;  
  29.   
  30. 返回值  
  31.   
  32. 返回此CString对象中与需要的子字符串或字符匹配的第一个字符的从零开始的索引;如果没有找到子字符串或字符则返回-1。  
  33.   
  34. 参数  
  35.   
  36. ch要搜索的单个字符。 lpszSub要搜索的子字符串。 nStart字符串中开始搜索的字符的索引,如果是0,则是从头开始搜索。如果nStart不是0,则位于nStart之前的字符不包括在搜索之内。 pstr指向要搜索的字符串的指针  
  37. / CString::Find( TCHAR ch )  
  38. CStrings( "abcdef" ); intn = s.Find( 'c' ); // 结果 n = 2 intf = s.Find( "de" ) ; // 结果 f = 3