public static void main( String[] a ) {
System.out.println( ifContainChinese( "你好 Earth" ) );
}
// java 判断字符串里是否包含中文字符
public static boolean ifContainChinese( String str ) {
Pattern p = Pattern.compile( "[\u4e00-\u9fa5]" );
Matcher m = p.matcher(str);
if ( m.find() ) {
return true;
}
return false;
}
本文介绍了一个简单的Java方法,用于检测字符串中是否包含中文字符。通过正则表达式匹配Unicode范围内的中文字符来实现这一功能。
1660

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



