C#处理数组Lenght相同但整体长度不同原因
原创 public int GetSeparateSubstring(string str)
{
string tempstr = str;
int count = 0;
int temp = 0;
for ( int i = 0; i < tempstr.length; i++)
{
string char = tempstr.substring(i, 1);
int bytecount = Encoding.Default.GetByteCount(char);
if (bytecount == 1)
{
temp++;
if (temp == 2)
{
count++;
temp = 0;
}
}
else if (bytecount > 1)
{
count++;
}
}
return count;
}
测试结果:
string str = "测试1122";
MessageBox.Show("str.Length = " + str.Length.ToString() + "-------" + "GetSeparateSubString = " + GetSeparateSubString(str).ToString());
输入结果:
str.Length = 6
GetSeparateSubString = 4
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
itfan123




