判断字符串中是否含有汉字
//true:无汉字 false:有汉字
boolean flag = (str.length() == str.getBytes().length);
\u后面加上十六进制代码来表示Unicode字符。
[\u4e00-\u9fa5] //匹配中文字符
^[1-9]\d*$ //匹配正整数
^[A-Za-z]+$ //匹配由26个英文字母组成的字符串
^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串
^[a-z]+$ //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串
String str1 = "java判断是否quan为汉字"
String str2 = "全为汉字"
String reg = "[\\u4e00-\\u9fa5]+"
boolean result1 = str1.matches(reg)//false
boolean result2 = str2.matches(reg)//true
//true:无汉字 false:有汉字
boolean flag = (str.length() == str.getBytes().length);
\u后面加上十六进制代码来表示Unicode字符。
[\u4e00-\u9fa5] //匹配中文字符
^[1-9]\d*$ //匹配正整数
^[A-Za-z]+$ //匹配由26个英文字母组成的字符串
^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串
^[a-z]+$ //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串
String str1 = "java判断是否quan为汉字"
String str2 = "全为汉字"
String reg = "[\\u4e00-\\u9fa5]+"
boolean result1 = str1.matches(reg)//false
boolean result2 = str2.matches(reg)//true