Judge whether the string is Chinese or English

Source: Internet
Author: User

Judge whether the string is Chinese or English

Import java. util. regex. Matcher; import java. util. regex. Pattern ;/****

* ClassName ShowChineseInUnicodeBlock *

*

* Description provides an idea to determine whether a string is Chinese or English *

*** @ Author wangxu wangx89@126.com *

* Date 06:45:35 *

* @ Version V1.0 **/public class ShowChineseInUnicodeBlock {public static void main (String [] args) {String str = "I love you ,!? ():; "",. "; Char [] charArray = str. toCharArray (); for (int I = 0; I <charArray. length; I ++) {isChinese (charArray [I]);} String chinese = "China god damn"; System. out. println (isContainChinese (chinese); String english = "dfafdabac"; System. out. println (isEnglish (english ));}/****

* Title: isChinese *

*

* Description: This function is used to print some characters to see what it belongs *

** @ Param c **/public static void isChinese (char c) {Character. unicodeBlock ub = Character. unicodeBlock. of (c); if (ub = Character. unicodeBlock. cjk_uniied_ideographs) {System. out. println (c + "-- cjk_uniied_ideographs");} else if (ub = Character. unicodeBlock. CJK_COMPATIBILITY_IDEOGRAPHS) {System. out. println (c + "-- CJK_COMPATIBILITY_IDEOGRAPHS");} else if (ub = Character. unicodeBlock. CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A) {// CJK uniied Ideographs Extension WikipediaUnicode extended Chinese characters // CJK uniied Ideographs Extension A, Japan, and South Korea Unified ideographic text extended area; ideographic Extension A // CJK Unified Ideographs Extension B C-Korea Unified ideographic Extension zone BSystem. out. println (c + "-- CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A");} else if (ub = Character. unicodeBlock. GENERAL_PUNCTUATION) {// General punctuation System. out. println (c + "-- GENERAL_PUNCTUATION");} else if (ub = Character. unicodeBlock. CJK_SYMBOLS_AND_PUNCTUATION) {System. out. println (c + "-- CJK_SYMBOLS_AND_PUNCTUATION");} else if (ub = Character. unicodeBlock. HALFWIDTH_AND_FULLWIDTH_FORMS) {System. out. println (c + "-- HALFWIDTH_AND_FULLWIDTH_FORMS") ;}} public static boolean isEnglish (String charaString) {return charaString. matches ("^ [a-zA-Z] *");} public static boolean isContainChinese (String str) {// check whether the String regEx = "[\ u4E00-\ u9FA5] +"; Pattern p = Pattern. compile (regEx); Matcher m = p. matcher (str); if (m. find () {return true;} else {return false ;}}}

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.