CString CutString(CString strText,int nLength)
{
int nASCC = 0;
if(strText.GetLength() <= nLength)
{
return strText;
}
////////////////////////////////////////////
for(int i = 0; i < nLength; i++)
{
if((BYTE)strText.GetAt(i) < 0x80)
{
nASCC ++;
}
}
////////////////////////////////////////////
if(nASCC % 2 == 0)
{
if(nLength % 2 == 0)
{
return strText.Mid(0,nLength);
}
else
{
return strText.Mid(0,nLength - 1);
}
}
else
{
if(nLength % 2 == 0)
{
return strText.Mid(0,nLength - 1);
}
else
{
return strText.Mid(0,nLength);
}
}
////////////////////////////////////////////
}
多字节字符集截取中文字符串
最新推荐文章于 2025-03-07 00:27:55 发布
本文介绍了一个用于处理CString对象的自定义函数CStringCutString,该函数能够根据指定长度nLength来智能截取字符串,同时考虑了字符编码的影响,确保返回的字符串内容完整且格式正确。
2756

被折叠的 条评论
为什么被折叠?



