1、Replace函數替換查找
Replace函數返回值:返回被替換的字符數。如果這個字符串沒有改變則返回零。
CString sTest="aabbccaadd";
int nCount=s.Replace("a","a");
nCount就是你的想要的值
CString::Replaceint Replace( TCHAR chOld, TCHAR chNew );int Replace( LPCTSTR lpszOld, LPCTSTR lpszNew );Return ValueThe number of replaced instances of the character. Zero if the string isn't changed.
2、標準函數 count_if
#include <iostream>#include <string>#include <functional>#include <algorithm>using namespace std;int main( void ){ const string a = " 12113"; cout << count_if( a.begin(), a.end(), bind2nd(equal_to<char>(),'1') ) << endl; return 0;}CString也一樣,但它沒有標準的迭代器,因此需要寫成count_if( (LPCTSTR)a, (LPCTSTR)a+a.GetLength(), bind2nd(equal_to<TCHAR>(),_T('某字符')) )
posted on 2013-02-19 14:34
王海光 閱讀(11926)
評論(2) 編輯 收藏 引用 所屬分類:
MFC