/// <summary>
/// 返回字符串的真实长度(汉字长度为2)
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static int ChinaLen(string str)
{
/*System.Text.ASCIIEncoding n = new System.Text.ASCIIEncoding();
byte[] b = n.GetBytes(str);
int length = 0; // l 为字符串的实际长度
for (int i = 0; i <= b.Length - 1; i++)
{
if (b[i] == 63) //判断是否为汉字或全脚符号
{
length++;
}
length++;
}
return length;
*/
byte[] myByte = System.Text.Encoding.Default.GetBytes(str);
return myByte.Length;
}
转载于:https://www.cnblogs.com/haver/articles/2106327.html