int GetLength( ) const; //得到字符串的字節數(並不都是個數,如漢字一個字佔兩個字節)
int strlen( const char *string ); //計算參數字符串裏面字節的個數並返回
BOOL IsEmpty( ) const; //如果字符串含有字符就返回假,如果是個空字符串就返回真
void Empty( ); //清空字符串,相當於把字符串的值賦爲""
注:
在函數後面加 const 的意思是:
如果一個類聲明瞭一個常量對象,這個對象只能使用後邊帶 const 這個的方法.
例1:
CString a,b,c,d;
a = "123456789";
b = "中國人";
c = "中國人12345";
a.GetLength(); //得到9個
b.GetLength(); //得到6個
c.GetLength(); //得到11個
例2:
CString a;
a = "123456789";
if (TRUE == a.IsEmpty()) //如果a爲空則把 "null_1" 打印在對話框中
{
MessageBox("null_1");
}
a.Empty(); //把a中的字符串清空
if (TRUE == a.IsEmpty()) //如果a爲空則把 "null_2" 打印在對話框中
{
MessageBox("null_2");
}
結果在對話框中打印的是 "null_2"