有一个字符串,其中包含字母和汉字,字母占一个字节,汉字占两个字节,写一个函数,求其中汉字的个数.提

jt4eo9 1年前 已收到1个回答 举报

x34fv521 幼苗

共回答了14个问题采纳率:92.9% 举报

public int strLength(string str)
{
int intresult = 0;
for (int i = 0; i < str.Length; i++)
{
char ci = str[i];
if ((int)ci < 0 || (int)ci > 255)
intresult += 1;
}
return intresult;
}

1年前

3
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.017 s. - webmaster@yulucn.com