Java string to determine the Chinese character and characters:
Package com.boco.synchrodata.util;
Public final class Stringutil {
/**
* Judging Chinese characters and symbols based on Unicode encoding
* @param c
* @return
*/
private static Boolean Ischinese (char c) {
Character.unicodeblock UB = Character.UnicodeBlock.of (c);
if (UB = = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| UB = = Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| UB = = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| UB = = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
|| UB = = Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| UB = = Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
|| UB = = Character.UnicodeBlock.GENERAL_PUNCTUATION) {
return true;
}
return false;
}
/**
* Complete judgment of Chinese characters and symbols
* @param strName
* @return
*/
public static Boolean Ischinese (String strName) {
char[] ch = strname.tochararray ();
for (int i = 0; i < ch.length; i++) {
char C = ch[i];
if (Ischinese (c)) {
return true;
}
}
return false;
}
/**
* Determine the number of Chinese to be included
* @param str
* @return
*/
public static long Lenwithchinese (String str) {
Remove the Chinese symbol (jdk1.5)
Final String _str = Str.replaceall ("[\\pP '" ""] "" ");
Long Count = 0;
char[] ch = _str.tochararray ();
for (int i = 0; i < ch.length; i++) {
char C = ch[i];
if (Ischinese (c)) {
count++;
}
}
return count;
}
/**
* @param args
*/
public static void Main (string[] args) {
}
}