/******************
确保串尾汉字的完整
******************/
int z_chi_nohalf(const char *s, int l)
{
int len = 0, i = 0;
/*
* while( *s && (l-- > 0) ) if( ! isascii( *(s++) ) ) i++;
* if( i % 2 ) *(s - 1) = 0;
* *s = 0;
*/
if( s == NULL || *s == 0 || l <= 0 ) return(0);
while( *s )
{
if( (*s & 0x80) == 0 )
{
i ++;
s ++;
len ++;
}
else
{
if( *(s + 1) == 0 ) break;
i += 2;
s += 2;
len += 2;
}
if( i == l ) break;
else if( i > l )
{
len -= 2;
break;
}
}
return(len);
}
最后
以上就是高兴羽毛最近收集整理的关于C、C++中文字符串截取,确保串尾汉字的完整的全部内容,更多相关C、C++中文字符串截取,确保串尾汉字内容请搜索靠谱客的其他文章。
发表评论 取消回复