09-04
06
Java判断中文的方法
作者:Java伴侣 日期:2009-04-06
1、
int count = 0;
String regEx = "[\\u4e00-\\u9fa5]";
// System.out.println(regEx);
String str = "字符串";
// System.out.println(str);
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
System.out.print("提取出来的中文有:");
while (m.find()) {
System.out.print(m.group(0)+" ");
}
System.out.println();
System.out.println(p.matches(regEx, str));
2、
String str1 = "字符串aa";
for(int i=0;i<str1.length();i++)
{
String test=str1.substring(i,i+1);
System.out.println(test);
if(test.matches("[\\u4E00-\\u9FA5]+"))
{
System.out.println("中文");
}
}
3、
System.out.println(str1.length()==str1.getBytes().length?”English”:”Contains Chinese”);
int count = 0;
String regEx = "[\\u4e00-\\u9fa5]";
// System.out.println(regEx);
String str = "字符串";
// System.out.println(str);
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
System.out.print("提取出来的中文有:");
while (m.find()) {
System.out.print(m.group(0)+" ");
}
System.out.println();
System.out.println(p.matches(regEx, str));
2、
String str1 = "字符串aa";
for(int i=0;i<str1.length();i++)
{
String test=str1.substring(i,i+1);
System.out.println(test);
if(test.matches("[\\u4E00-\\u9FA5]+"))
{
System.out.println("中文");
}
}
3、
System.out.println(str1.length()==str1.getBytes().length?”English”:”Contains Chinese”);
评论: 0 | 引用: 0 | 查看次数: 456
发表评论