最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
判断字符串是否为中文
时间:2022-06-25 04:05:15 编辑:袖梨 来源:一聚教程网
下面简单的介绍了php教程和asp教程.net来判断字符串是否含有中文的代码。
$str = "中文";
if (preg_match("/[x7f-xff]/", $str)) {
echo "含有中文";
}else{
echo "没有中文";
}
或
$pattern = '/[^x00-x80]/';
if(preg_match($pattern,$str)){
echo "含有中文";
}else{
echo "没有中文";
}
/// 检测是否有中文字符
///
/// 输入字符串
///是否有中文字符
public static bool IsIncludeChinese(string inputData)
{
Regex regex = new Regex("[u4e00-u9fa5]");
Match m = regex.Match(inputData);
return m.Success;
}