public bool IsChineseCharacter (string str)
{
Regex regChina = new Regex ("^[^\x00-\xFF]");
Regex regEnglish = new Regex ("^[a-zA-Z]");
if (regEnglish.IsMatch (str)) {
return false;
}
else if (regChina.IsMatch (str)) {
return true;
}
else
{
return false;
}
//byte [] byte_len = System.Text.Encoding.Default.GetBytes (ch);
//if (byte_len.Length == 2) { return true; }
}Determine whether the text is in Chinese or English
最新推荐文章于 2024-09-06 09:49:11 发布
本文介绍了一种使用正则表达式的方法来判断输入的字符串是否全为中文字符。通过定义两个正则表达式,分别匹配英文字符和中文字符,实现了对字符串类型的简单判断。
417

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



