怎么截取CString类型中前20个"字"(包括汉字),然后返回给CString类型变量? 如CString str1("1112AAA测试汉字ssss,,ffffffffffffffffffwwwwwwwwd地工");.................获得的结果CString str2 等于1112AAA测试汉字ssss,,fff 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int nCharNum = 0;for(int i=0;i<str1.GetLength();i++){ char ch = str1.GetAt(i); if(ch & 0x80) i++; nCharNum ++; if(nCharNum >= 20) break;}str2 = str1.Left(i); CString str1("1112AAA测试汉字ssss,,ffffffffffffffffffwwwwwwwwd地工");// 如果不是UNICODE环境下CStringW str2(str1);str2.Left(20);// 如果 UNICODE环境下str1.Left(20); CString str1("1112AAA测试汉字ssss,,ffffffffffffffffffwwwwwwwwd地工");int i;LPCTSTR psz = str1;for (i=0;i<20;++i){ if (*psz == 0) break; psz = ::CharNext (psz);};str1 = str1.Left (psz-(LPCTSTR)str1); 支持: xstring(麻雀) happyparrot(快乐鹦鹉) 对“,”的处理好像不太对。 非UNICODE下的不说了,直接用GetLength()就可以UNICODE下: CString csDemo="111我的测试!222aaabbb"; WCHAR wcSend[1024]; TCHAR tcSend[1024]; int iLength=csDemo.GetLength(); strcpy(tcSend,csDemo.GetBuffer(csDemo.GetLength()));csDemo.ReleaseBuffer(); MultiByteToWideChar(CP_ACP,0,tcSend,-1, wcSend,1024) wcsset(wcSend+iLength,'\0'); int iTCLength=WideCharToMultiByte(CP_ACP,0,wcSend,-1, tcSend,1024,NULL,false); tcSend[iTCLength]='\0'; int iMyLengthResult=strlen(tcSend); iMyLengthResult就是你要的结果了 看错了,以为你要取得长度,xstring说的我以前就这么用的,可以的 happyparrot(快乐鹦鹉)和xstring(麻雀) 的处理结果对于汉字来说都是没什么问题的 编写了一个shell 在windows 右键菜单里添加自己的菜单项 com类添加变量写上m_AlphaInstance[2]//报含有非法字符??? VC中文件夹的传输 我的formview无法找到wm_ctlcolor? 纯灌水,散分 关于文本显示、移动、删除的问题,有知道方法,请进,谢谢! 这个贴包含另外一个贴的80分:CListCtrl的高难度问题,onclick 执行2次 ==已知曲线上一些点的坐标,怎么把它连接成光滑的曲线???== 一个非常简单的问题,关于对话框的问题!在线等待! 多线程下的异步操作 开发数据库用VC还是用C++BUILDER 存储过程的问题,急
for(int i=0;i<str1.GetLength();i++)
{
char ch = str1.GetAt(i);
if(ch & 0x80)
i++;
nCharNum ++;
if(nCharNum >= 20)
break;
}
str2 = str1.Left(i);
// 如果不是UNICODE环境下
CStringW str2(str1);
str2.Left(20);// 如果 UNICODE环境下
str1.Left(20);
LPCTSTR psz = str1;
for (i=0;i<20;++i)
{
if (*psz == 0)
break;
psz = ::CharNext (psz);
};
str1 = str1.Left (psz-(LPCTSTR)str1);
UNICODE下:
CString csDemo="111我的测试!222aaabbb";
WCHAR wcSend[1024];
TCHAR tcSend[1024];
int iLength=csDemo.GetLength();
strcpy(tcSend,csDemo.GetBuffer(csDemo.GetLength()));csDemo.ReleaseBuffer();
MultiByteToWideChar(CP_ACP,0,tcSend,-1, wcSend,1024)
wcsset(wcSend+iLength,'\0');
int iTCLength=WideCharToMultiByte(CP_ACP,0,wcSend,-1, tcSend,1024,NULL,false);
tcSend[iTCLength]='\0';
int iMyLengthResult=strlen(tcSend);
iMyLengthResult就是你要的结果了