解决办法如下,str为要检测的字符串:
ASCIIEncoding n = new ASCIIEncoding();
byte[] b = n.GetBytes(str);
int l = 0; // l 为字符串之实际长度
for (int i=0;i <= b.Length-1;i++)
{
if (b[i] ==63) //判断是否为汉字或全脚符号
{
l++;
}
l++;
}
ASCIIEncoding n = new ASCIIEncoding();
byte[] b = n.GetBytes(str);
int l = 0; // l 为字符串之实际长度
for (int i=0;i <= b.Length-1;i++)
{
if (b[i] ==63) //判断是否为汉字或全脚符号
{
l++;
}
l++;
}
本文介绍了一种用于检测字符串中特殊字符如汉字或全角符号的算法。通过ASCII编码转换及字节判断,实现对字符串的实际长度计算。
2528

被折叠的 条评论
为什么被折叠?



