Several ways to determine whether Char is Chinese in Java

Source: Internet
Author: User

1, Method one

Java code
    1. char c = ' a ';
    2. if ((c >= 0x4e00) && (c <= 0x9fbb)) {
    3. System.out.println ("is Chinese");
    4. }

The above method is simple, but can only judge whether it is Chinese, but can not determine whether it is Chinese punctuation.

The following method is comprehensive, the Chinese character punctuation can be judged

2. Method Two

Java code
  1. Private Static final boolean Ischinese (char c) {
  2. Character.unicodeblock UB = Character.UnicodeBlock.of (c);
  3. if (UB = = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
  4. || UB = = Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
  5. || UB = = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
  6. || UB = = Character.UnicodeBlock.GENERAL_PUNCTUATION
  7. || UB = = Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
  8. || UB = = Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
  9. return true;
  10. }
  11. return false;
  12. }
Reviews 1 Floor jetmah 2012-06-20 block = = cjk_unified_ideographs//CJK Unified Ideographs
|| Block = = cjk_compatibility_ideographs//CJK Compatible characters
|| Block = = cjk_unified_ideographs_extension_a//CJK Unified Ideographs Extension A
|| Block = = general_punctuation//General punctuation, judging Chinese "No.
|| Block = = cjk_symbols_and_punctuation//symbols and punctuation, judging the Chinese. No.
|| Block = = halfwidth_and_fullwidth_forms//half-width and full-width characters, judging the Chinese, number

Several ways to determine whether Char is Chinese in Java

Related Article

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.