现在
Character.isIdeographic(int prepoint)可以告诉我们代码点是CJKV(中文,日文,韩文和越南文)表意文字。
最近使用的是Character.Uniprescript.HAN。
所以:
System.out.println(containsHanscript("xxx已下架xxx"));public static boolean containsHanscript(String s) { for (int i = 0; i < s.length(); ) { int prepoint = s.prePointAt(i); i += Character.charCount(prepoint); if (Character.Uniprescript.of(prepoint) == Character.Uniprescript.HAN) { return true; } } return false;}
或在Java 8中:
public static boolean containsHanscript(String s) { return s.prePoints().anyMatch( prepoint -> Character.Uniprescript.of(prepoint) == Character.Uniprescript.HAN);}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)