java提取字串中的漢字
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Code3 {
public static void main(String[] args) {
int count = 0;
String regEx = "[\\u4e00-\\u9fa5]";
// System.out.println(regEx);
String str = "Internet網路is真好 very good ^_^!";
// System.out.println(str);
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
System.out.print("提取出來的中文有:");
System.out.println(m.groupCount());
while (m.find()) {
System.out.print(m.group());
}
System.out.println();
String str1 = "歡迎光臨我的JAVA世紀網www.java123.net";
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str1.length(); i++) {
if ((str1.charAt(i)+"").getBytes().length>1) {
sb.append(str1.charAt(i));
}
}
System.out.println(sb);
}
}