class Program
{
static void Main(string[] args)
{
GetStrLength("可以f");
Console.ReadKey();
}
private static int GetStrLength(string str)
{
if (string.IsNullOrEmpty(str)) return 0;
ASCIIEncoding ascii = new ASCIIEncoding();
int tempLen = 0;
byte[] s = ascii.GetBytes(str);
for (int i = 0; i < s.Length; i++)
{
if ((int)s[i] == 63)
{
tempLen += 2;
}
else
{
tempLen += 1;
}
}
Console.WriteLine("当前字符串长度为:" + tempLen);
return tempLen;
}
输出长度为5,一个中文字占两位