C#字符串的全角是指用二个字节来表示的一个字符
C#字符串的半角是用一个字节来表示的一个字符
这样的话我们就可以用string.length 和System.text.Encoding.Default.GetByteCount来判断
其中string.length表示C#字符串字符串的字符数,
System.text.Encoding.Default.GetByteCount表示字符串的字节数。
}
else
{
return false;
if (2 * checkString.Length == Encoding.Default.GetByteCount(checkString))
{
return true;
}
else
{
C#字符串的半角是用一个字节来表示的一个字符
这样的话我们就可以用string.length 和System.text.Encoding.Default.GetByteCount来判断
其中string.length表示C#字符串字符串的字符数,
System.text.Encoding.Default.GetByteCount表示字符串的字节数。
判断半角如下:
if (checkString.Length == Encoding.Default.GetByteCount(checkString))
{
return true;}
else
{
return false;
}
if (2 * checkString.Length == Encoding.Default.GetByteCount(checkString))
{
return true;
}
else
{
return false;
}
本文详细介绍了如何使用C#语言通过string.length和System.text.Encoding.Default.GetByteCount来判断字符串是全角还是半角。通过简单的条件判断,实现对字符串角型的快速识别。
603

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



