Wednesday, January 12, 2022

Salesforce Apex code to detect Chinese or Japanese characters 在字串中尋找漢字 包含中文字 或 日文字

 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

Next year SF migration plan : moving out customer account to AWS , and call SF data with service account

 👀 The most challenging part is about those function with user verification. My service cloud with MIAW chat , nearly redo due to the user ...