http://hi.baidu.com/jwz_hz/blog/item/9b79bc596cb144d89c82049c.html
1.char *strtok(char *s, char *delim);
功能:分解字符串为一组字符串。s为要分解的字符串,delim为分隔符字符串。
说明:首次调用时,s指向要分解的字符串,之后再次调用要把s设成NULL。
2.<string.h> or <wchar.h>or<mbstring.h>
int _stricmp(
const char *string1,
const char *string2
);
int _wcsicmp(
const wchar_t *string1,
const wchar_t *string2
);
int _mbsicmp(
const unsigned char *string1,
const unsigned char *string2
);
int _stricmp_l(
const char *string1,
const char *string2,
_locale_t locale
);
int _wcsicmp_l(
const wchar_t *string1,
const wchar_t *string2,
_locale_t locale
);
int _mbsicmp_l(
const unsigned char *string1,
const unsigned char *string2,
_locale_t locale
);
这几个函数对字符串做比较的时候会先把字符串转换成小写,然后做比较。如:
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";
strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2
3数据类型转换
TCHAR-->bstr BSTR bsFileName=::T2BSTR(szFileName);
bstr-->ATL::CString CString strFileName=bsFileName;
Atl::CString-->const char * int nFileNameLen=strFileName.GetLength()*4+1; char *buffer=new char[nFileNameLen]; strcpy(buffer,CT2A(strFileName));
bstr-->tchar BSTR bstr; TCHAR *pt = OLE2T(bstr); 或者 #include <atlconv.h> BSTR bstr; USES_CONVERSION; TCHAR *pt = OLE2T(bstr); 或者 BSTR bstrUpdate = _com_util::ConvertStringToBSTR(XXX); SysFreeString(bstrUpdate);
CString->TCHAR*的转化可以用函数GetBuff()
函数原型为:LPTSTR GetBuffer( int nMinBufLength );CString str("CString"); TCHAR* szMsg = new TCHAR[100]; //其参数为CString字符串的长度 szMsg = str.GetBuffer(str.GetLength()); str.ReleaseBuffer(); delete []szMsg; szMsg = NULL;
TCHAR*->CString的转化
TCHAR szTchar[18] = L"TCHAR"; CString str; str.Format(_T("%s"),szTchar);
Unicode和ANSI之间转换
namespace _com::util
{
//char*-->bstr
BSTR ConvertStringToBSTR(const char * pSrc);//反过来用ConvertBSTRToString
}