CString

CString類
一、常用成員函數
1.int GetLength( ) const;
說明:獲取CString類對象包含字符串的長度(字符數)。
2.BOOL IsEmpty( ) const;
說明:測試CString類對象包含的字符串是否爲空。
3.void Empty( );
說明:使CString類對象包含的字符串爲空字符串。
4.TCHAR GetAt( int nIndex ) const;
說明:獲得字符串指定位置處的字符。
5.TCHAR operator []( int nIndex ) const;
說明:獲得字符串指定位置處的字符,作用和GetAt()一樣。
6.void SetAt( int nIndex, TCHAR ch );
說明:設定字符串指定位置處的字符。
7.operator LPCTSTR ( ) const;
說明:返回指向儲存在CString類對象內的字符串指針。
8.Mid
Mid函數有兩個重載函數:
CString Mid( int nFirst ) const; throw( CMemoryException );
獲取從nFirst位置開始的子串。
CString Mid( int nFirst, int nCount ) const; throw( CMemoryException );
獲取從nFirst位置開始包含nCount個字符的子串。
9.CString Left( int nCount ) const;throw( CMemoryException );
說明:獲取字符串左邊nCount長度的字符串。
10.CString Right( int nCount ) const; throw( CMemoryException );
說明:獲取字符串右邊nCount長度的字符串。
11.CString SpanIncluding( LPCTSTR lpszCharSet ) const;throw( CMemoryException );
說明:從字符串中提取包含在指定字符集lpszCharSet中的字符的子串。它從字符串的第一個字符開始,直到遇到不屬於lpszCharSet中的字符爲止。
12.CString SpanExcluding( LPCTSTR lpszCharSet ) const;throw( CMemoryException );
說明:從字符串中提取不包含在指定字符集lpszCharSet中的字符的子串。
13.MakeUpper
將字符串中所有的字符全部轉化成大寫形式。
14.MakeLower
將字符串中所有的字符全部轉化成小寫形式。
15.MakeReverse
將字符串倒置,即將字符的順序顛倒,第一個字符變成最後一個字符。
16.int Replace( TCHAR chOld, TCHAR chNew );
int Replace( LPCTSTR lpszOld, LPCTSTR lpszNew );
說明:將字符串中的字符chOld或字符子串lpszOld替換成新的字符chNew或字符串lpszNew。
17.      void CString::TrimLeft( TCHAR chTarget );
void CString::TrimLeft( LPCTSTR lpszTargets );
說明:刪除字符串左邊開頭的字符或字符子串,參數缺省時刪除左邊的空格。
18.void CString::TrimRight( TCHAR chTarget );
void CString::TrimRight( LPCTSTR lpszTargets );
說明:刪除字符串右邊開頭的字符或字符子串,參數缺省時刪除右邊的空格。
19.Find
原型:
int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR pstr, int nStart ) const;
說明:在字符串中查找指定的字符或字符串。參數ch爲要查找的字符;lpszSub爲要查找的字符子串;nStart指定查找的起始位置,如缺省爲從最左邊開始;pstr指向欲查找子串的指針。
20.ReverseFind
原型:int ReverseFind( TCHAR ch ) const;
說明:返回字符串中最後一個和指定的字符匹配的字符的下標。
21.FindOneOf
原型:int FindOneOf( LPCTSTR lpszCharSet ) const;
說明:在字符串中查找第一個和指定的字符集lpszCharSet中任何一個字符匹配的字符的位置。
22.比較運算符
CString類重載了“==”、“!=”、“>=”、“>”、“<=”、“<”等比較運算符,可用於兩個字符串間的各種比較運算,比較時區分大小寫。
23.Compare
原形:int Compare( LPCTSTR lpsz ) const;
說明:比較兩個字符串,如果兩個字符串相等,返回值等於0;如果本對象大於參數字符串,返回值大於0;如果本對象小於參數字符串,返回值小於0,比較時區分大小寫。
24.CompareNoCase
原型:int CompareNoCase( LPCTSTR lpsz ) const;
說明:與Compare函數類似,不同的是在忽略字符大小寫的情況下比較兩個字符串。
25.operator =
說明:將一個新的值賦予CString對象。
26.operator +
說明:將兩個字符串合併成一個新的字符串。在兩個參數中必須有一個是CString類型的,而另一個參數可以是字符、字符指針或CString類型對象。
27.operator +=
說明:在一個字符串的後面再添加一個字符串或一個字符。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章