標籤:
it |
分類: 妞的MFC界面開發學習 |
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