CString类的使用
对象初始化
CString str1;
CString str2(_T("hello"));
CString str3 = _T("hello");
TCHAR szBuf[] = _T("ABC");
CString str4(szBuf);
CString str5 = szBuf;
TCHAR *pChar = _T("CHINA");
CString str6(pChar);
CString str7 = pChar;
CString str8(str7);
CString str9 = str7;
对象基本操作
CString str(_T("hello,kitty--中国"));
int len = str.GetLength();
bool flag1 = str.IsEmpty();
bool flag2 = CString().IsEmpty();
str.MakeUpper();
MessageBox(str);
str.MakeLower();
MessageBox(str);
str.MakeReverse();
MessageBox(str);
对象拼接
CString str1 = TEXT("hello");
CString str2 = TEXT("kitty");
CString str3 = str1 + TEXT(",") + str2;
MessageBox(str3);
str3 += CString(TEXT(": china"));
MessageBox(str3);
TCHAR szBuf[] = TEXT("AAA");
str3 += szBuf;
MessageBox(str3);
TCHAR *pTChar = TEXT("BBB");
str3 += pTChar;
MessageBox(str3);
字符串比较
CString s1(TEXT("ABC"));
CString s2 = TEXT("BBB");
TCHAR szBuf[] = TEXT("ABC");
TCHAR *pTChar = TEXT("abc");
bool flag = s1 == s2;
flag = s1 == szBuf;
flag = s1 == pTChar;
int i = 0;
i = s1.Compare(szBuf);
i =