CString::Empty
Void Empty( );
没有返回值 清空操作;
CString::Format
void Format( LPCTSTR lpszFormat, ... );
void Format( UINT nFormatID, ... );
Parameters参数
lpszFormat
A format-control string.格式控制字符串。
nFormatID
The string resource identifier that contains the format-control string.包含格式控制字符串的字符串资源标记。
CString str;
str.Format(_T("Floating point: %.2f\n"), 12345.12345);
_tprintf("%s", (LPCTSTR) str);
str.Format(_T("Left-justified integer: %.6d\n"), 35);
_tprintf("%s", (LPCTSTR) str);
str.Format(IDS_SCORE, 5, 3);
_tprintf("%s", (LPCTSTR) str);
输出:
Floating point: 12345.12
Left-justified integer: 000035
Penguins: 5
Flyers : 3
CString::FormatV
void FormatV( LPCTSTR lpszFormat, va_list argList );
Parameters参数
lpszFormat
A format-control string.格式控制字符串。
argList
A list of arguments to be passed.
被传递的一列参数。
CString::FormatMessage
void FormatMessage( LPCTSTR lpszFormat, ... );
void FormatMessage( UINT nFormatID, ... );
Parameters参数
lpszFormat
Points to the format-control string. It will be scanned for inserts and formatted accordingly. The format string is similar to run-time function printf-style format strings, except it allows for the parameters to be inserted in an arbitrary order.
格式控制字符串指针。其作用是确定插入的字符及其格式,除了允许参数可以按照任意的顺序插入外,和(运行函数)printf的格式相同。
nFormatID
The string resource identifier that contains the unformatted message text.
包含无格式的消息正文的字符串资源标识符(?)。
CString::IsEmpty
BOOL IsEmpty( ) const;
返回值
如果CString 对象的长度为0,则返回非零值;否则返回0。
Delete
int Delete( int nIndex, int nCount = 1 )
返回值是被删除前的字符串的长度,nIndex是第一个被删除的字符,nCount是一次删除几个字符。根据我实验得出的结果:当nCount>字符串的长度时会出错,当nCount过大,没有足够的字符删除时,此函数不执行。
FindOneOf
int FindOneOf( LPCTSTR lpszCharSet ) const;
此函数的功能是在查找lpszCharSet中的任意一个字符,查到一个就把位置返回,没有查到返回0。如:
CString str = "0123456789";
int x = str.FindOneOf("31");
x的值是1。
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 从那里开始搜索。如:
CString str = "0123456789";
int x = str.Find("34",4);
返回的值是-1.
GetAt
TCHAR GetAt( int nIndex ) const;
返回标号为nIndex的字符,你可以把字符串理解为一个数组,GetAt类似于[].注意nIndex的范围,如果不合适会有调试错误。
Insert
int Insert( int nIndex, TCHAR ch )
int Insert( int nIndex, LPCTSTR pstr )
返回修改后的长度,nIndex字符(或字符串)插入后的标号。
例子: CString str("HockeyBest");
int n = str.Insert(6, "is ");
Left
CString Left( int nCount ) const;
返回的字符串的前nCount个字符。
Right与Left类似
MakeLower ,MakeUpper改变字符的大小写
MakeReverse字符倒置,如:
CString str = "X0123456789";
str.MakeReverse();
str变为"9876543210X"
CString::Replace
int Replace( TCHAR chOld, TCHAR chNew );
int Replace( LPCTSTR lpszOld, LPCTSTR lpszNew );
Return Value返回值
The number of replaced instances of the character. Zero if the string isn't changed.
该函数返回替换的字符数量。如果原对象没有改变则返回0。
Parameters参数
chOld
The character to be replaced by chNew.
将要被chNew所代替的字符。
chNew
The character replacing chOld.
用来替换chOld的字符。
lpszOld
A pointer to a string containing the character to be replaced by lpszNew.
lpszOld是一个指向字符串的指针,它所包含的字符将被lpszNew所代替。
lpszNew
A pointer to a string containing the character replacing lpszOld.
lpszNew是一个指向字符串的指针,它所包含的字符用来替换lpszOld。
例子:CString strBang("Everybody likes ice hockey");
n = strBang.Replace("hockey", "golf");
+=
const CString& operator +=( const CString& string );
const CString& operator +=( TCHAR ch );
const CString& operator +=( LPCTSTR lpsz );
将参数合并到自己身上。
如: CString str = "0123456789";
str+="ha";
str为"0123456789ha";
str[]
TCHAR operator []( int nIndex ) const;
象处理字符数组一样处理字符串。
注意是只读的。
CString str = "0123456789";
str[0]='x';
是错误的。
TrimLeft,TrimRight
void TrimLeft( );
void CString::TrimLeft( TCHAR chTarget );
void CString::TrimLeft( LPCTSTR lpszTargets );
void TrimRight( );
void CString::TrimRight( TCHAR chTarget );
void CString::TrimRight( LPCTSTR lpszTargets );
CString str = "\n\t a";
str.TrimLeft();
str为“a”;
如果没有参数,从左删除字符(\n\t空格等),至到遇到一个非此类字符.
当然你也可以指定删除那些字符.
如果指定的参数是字符串,那么遇上其中的一个字符就删除.
CString str = "abbcadbabcadb ";
str.TrimLeft("ab");
结果"cadbabcadb "
int CString::Remove( TCHAR ch );
ch删除的字符.
返回删除字符的个数,有多个时都会删除.
CString str("This is a test.");
int n = str.Remove('t');
CString 与char []之间的转换.
char str[100] = ”str”;
CString sstr = “sstr”;
str.Format(“%s”,str);
str = LPCTSTR sstr;
strcpy(str,(LPCTSTR)sstr);
如果是赋值,则要:
CString s(_T("This is a test "));
LPTSTR p = s.GetBuffer();
// 在这里添加使用p的代码
if(p != NULL) *p = _T('\0');
s.ReleaseBuffer();
// 使用完后及时释放,以便能使用其它的CString成员函数
str的值变了.
将NULL字节放入CString中
Void Empty( );
没有返回值 清空操作;
CString::Format
void Format( LPCTSTR lpszFormat, ... );
void Format( UINT nFormatID, ... );
Parameters参数
lpszFormat
A format-control string.格式控制字符串。
nFormatID
The string resource identifier that contains the format-control string.包含格式控制字符串的字符串资源标记。
CString str;
str.Format(_T("Floating point: %.2f\n"), 12345.12345);
_tprintf("%s", (LPCTSTR) str);
str.Format(_T("Left-justified integer: %.6d\n"), 35);
_tprintf("%s", (LPCTSTR) str);
str.Format(IDS_SCORE, 5, 3);
_tprintf("%s", (LPCTSTR) str);
输出:
Floating point: 12345.12
Left-justified integer: 000035
Penguins: 5
Flyers : 3
CString::FormatV
void FormatV( LPCTSTR lpszFormat, va_list argList );
Parameters参数
lpszFormat
A format-control string.格式控制字符串。
argList
A list of arguments to be passed.
被传递的一列参数。
CString::FormatMessage
void FormatMessage( LPCTSTR lpszFormat, ... );
void FormatMessage( UINT nFormatID, ... );
Parameters参数
lpszFormat
Points to the format-control string. It will be scanned for inserts and formatted accordingly. The format string is similar to run-time function printf-style format strings, except it allows for the parameters to be inserted in an arbitrary order.
格式控制字符串指针。其作用是确定插入的字符及其格式,除了允许参数可以按照任意的顺序插入外,和(运行函数)printf的格式相同。
nFormatID
The string resource identifier that contains the unformatted message text.
包含无格式的消息正文的字符串资源标识符(?)。
CString::IsEmpty
BOOL IsEmpty( ) const;
返回值
如果CString 对象的长度为0,则返回非零值;否则返回0。
Delete
int Delete( int nIndex, int nCount = 1 )
返回值是被删除前的字符串的长度,nIndex是第一个被删除的字符,nCount是一次删除几个字符。根据我实验得出的结果:当nCount>字符串的长度时会出错,当nCount过大,没有足够的字符删除时,此函数不执行。
FindOneOf
int FindOneOf( LPCTSTR lpszCharSet ) const;
此函数的功能是在查找lpszCharSet中的任意一个字符,查到一个就把位置返回,没有查到返回0。如:
CString str = "0123456789";
int x = str.FindOneOf("31");
x的值是1。
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 从那里开始搜索。如:
CString str = "0123456789";
int x = str.Find("34",4);
返回的值是-1.
GetAt
TCHAR GetAt( int nIndex ) const;
返回标号为nIndex的字符,你可以把字符串理解为一个数组,GetAt类似于[].注意nIndex的范围,如果不合适会有调试错误。
Insert
int Insert( int nIndex, TCHAR ch )
int Insert( int nIndex, LPCTSTR pstr )
返回修改后的长度,nIndex字符(或字符串)插入后的标号。
例子: CString str("HockeyBest");
int n = str.Insert(6, "is ");
Left
CString Left( int nCount ) const;
返回的字符串的前nCount个字符。
Right与Left类似
MakeLower ,MakeUpper改变字符的大小写
MakeReverse字符倒置,如:
CString str = "X0123456789";
str.MakeReverse();
str变为"9876543210X"
CString::Replace
int Replace( TCHAR chOld, TCHAR chNew );
int Replace( LPCTSTR lpszOld, LPCTSTR lpszNew );
Return Value返回值
The number of replaced instances of the character. Zero if the string isn't changed.
该函数返回替换的字符数量。如果原对象没有改变则返回0。
Parameters参数
chOld
The character to be replaced by chNew.
将要被chNew所代替的字符。
chNew
The character replacing chOld.
用来替换chOld的字符。
lpszOld
A pointer to a string containing the character to be replaced by lpszNew.
lpszOld是一个指向字符串的指针,它所包含的字符将被lpszNew所代替。
lpszNew
A pointer to a string containing the character replacing lpszOld.
lpszNew是一个指向字符串的指针,它所包含的字符用来替换lpszOld。
例子:CString strBang("Everybody likes ice hockey");
n = strBang.Replace("hockey", "golf");
+=
const CString& operator +=( const CString& string );
const CString& operator +=( TCHAR ch );
const CString& operator +=( LPCTSTR lpsz );
将参数合并到自己身上。
如: CString str = "0123456789";
str+="ha";
str为"0123456789ha";
str[]
TCHAR operator []( int nIndex ) const;
象处理字符数组一样处理字符串。
注意是只读的。
CString str = "0123456789";
str[0]='x';
是错误的。
TrimLeft,TrimRight
void TrimLeft( );
void CString::TrimLeft( TCHAR chTarget );
void CString::TrimLeft( LPCTSTR lpszTargets );
void TrimRight( );
void CString::TrimRight( TCHAR chTarget );
void CString::TrimRight( LPCTSTR lpszTargets );
CString str = "\n\t a";
str.TrimLeft();
str为“a”;
如果没有参数,从左删除字符(\n\t空格等),至到遇到一个非此类字符.
当然你也可以指定删除那些字符.
如果指定的参数是字符串,那么遇上其中的一个字符就删除.
CString str = "abbcadbabcadb ";
str.TrimLeft("ab");
结果"cadbabcadb "
int CString::Remove( TCHAR ch );
ch删除的字符.
返回删除字符的个数,有多个时都会删除.
CString str("This is a test.");
int n = str.Remove('t');
CString 与char []之间的转换.
char str[100] = ”str”;
CString sstr = “sstr”;
str.Format(“%s”,str);
str = LPCTSTR sstr;
strcpy(str,(LPCTSTR)sstr);
如果是赋值,则要:
CString s(_T("This is a test "));
LPTSTR p = s.GetBuffer();
// 在这里添加使用p的代码
if(p != NULL) *p = _T('\0');
s.ReleaseBuffer();
// 使用完后及时释放,以便能使用其它的CString成员函数
str的值变了.
将NULL字节放入CString中