Sometimes we have to identify the language character inside string . Code below shows how to use Apex code to identify whether a specific string contains "Hanzi" or not .
#Please be reminded that "Hanzi" NOT just detect Chinese characters , it may also include Japanese Hanzi.
1 2 3 4 5 6 | //true if contain chinese or japanese hanzi public static Boolean containsChineseCharacters(String InputString){ Pattern p = Pattern.compile('\\p{IsHan}'); Matcher m = p.matcher( InputString ); return m.find(); } |
No comments:
Post a Comment