全角占用二个字节半角占用一个字节 用string.length 和System.text.Encoding.Default.GetByteCount其中string.length表示字符串的字符数,System.text.Encoding.Default.GetByteCount表示字符串的字节数。

1、判断半角(是半角则true)

1
2
3
if (checkString.Length ==
Encoding.Default.GetByteCount(checkString))
{ return true ; } else { return false ; }


2、全角(是全角则返回true)

1
2
3
if (2 * checkString.Length ==
Encoding.Default.GetByteCount(checkString))
{ return true ; } else { return false ; }

转载优特建站:http://www.youtiy.com/Articles/Item.aspx?Id=278