Java string to judge the Chinese character and its characters __ system operation dimension

Source: Internet
Author: User

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) {


}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.