The method code for java to determine whether a string is Chinese is as follows:
String string; //需要判断的内容 if(string.matches("[\u4E00-\u9FA5]+")){ ToastUtils.Toast(Activity_authentication.this, "内容是中文"); }else{ ToastUtils.Toast(Activity_authentication.this, "内容包含非中文"); }
Unicode is a unified global text encoding. It assigns a unique code to each character of various texts in the world, enabling cross-language and cross-platform applications.
Chinese users are most often exposed to the Unicode encoding of Chinese characters. The number of Chinese characters is huge. There are thousands of Chinese characters in daily use. When adding rare characters, the number reaches tens of thousands.
matches() method is used to detect whether a string matches a given regular expression.
The str.matches(regex) form of calling this method produces exactly the same result as the following expression:
Pattern.matches(regex, str)
Syntax
public boolean matches(String regex)
Parameters: regex -- Match string regular expression.
Return value: Returns true when the string matches the given regular expression.
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of Java determines whether a string is Chinese. For more information, please follow other related articles on the PHP Chinese website!