首页 > 编程语言 > 详细

MFC在多字节环境下计算unicode串长度和截断中文字符

时间:2019-10-14 10:08:10      阅读:153      评论:0      收藏:0      [点我收藏+]
 1 CString CmuchbyteDlg::GetChinese(int size,CString &str)
 2 {
 3 
 4  DWORD dBufSize = MultiByteToWideChar(CP_ACP, 0, str, str.GetLength(), NULL, 0);
 5 
 6  wchar_t * dBuf=new wchar_t[dBufSize];
 7  //初始化
 8  wmemset(dBuf,0,dBufSize);
 9 
10  int nRet = MultiByteToWideChar(CP_ACP, 0, str,  str.GetLength(), dBuf, dBufSize);
11 
12  CString Ansstr = "";
13  int ans = 0;
14  for(int i = 0;i < nRet;i++)
15  {
16   if(dBuf[i] < 0 || dBuf[i] > 0x80)
17   {
18    if(ans >= size)
19     break;
20    ans ++;
21    CString cstring(dBuf[i]);
22    Ansstr += cstring;
23   }
24  }
25  return Ansstr;
26 }

 

MFC在多字节环境下计算unicode串长度和截断中文字符

原文:https://www.cnblogs.com/Jawen/p/11669658.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!