读书人

小弟我已经转换为宽字符了为何find还

发布时间: 2012-01-12 22:11:58 作者: rapoo

我已经转换为宽字符了,为何find还返回4?
int nLen;
CString str,msg = "ab我的c ";


nLen = MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,msg,-1,NULL,0) - 1;//6

nLen = msg.Find( "的 ");

str.Format( "%d ",nLen);


AfxMessageBox(str);


我已经转换为宽字符了,为何find还返回4?



[解决办法]
还没有转化为宽字符。
wchar_t wChar[50];
memset(wChar, 0, sizeof(wChar));
nLen = MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,msg,-1,NULL,0); //得到宽字节的长度
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,msg,-1,wChar,nlen);

读书人网 >VC/MFC

热点推荐