[JAVA] isSurrogate(char) 与 isSupplementaryCodePoint(int)

直接上代码:

String o = new String("𝕆");
String a = "ab"; 

println(Character.isSurrogate(o.charAt(0)));// true println(Character.isSurrogate(o.charAt(1)));// true 

println(Character.isSurrogate(a.charAt(0)));// false println(Character.isSurrogate(a.charAt(1)));// false 

println(Character.isSupplementaryCodePoint(o.codePointAt(0)));// true println(Character.isSupplementaryCodePoint(o.codePointAt(1)));// false 

println(Character.isSupplementaryCodePoint(a.codePointAt(0)));// false println(Character.isSupplementaryCodePoint(a.codePointAt(1)));// false

简单来说,对于isSurrogate(char),char对应代码单元是用于表示辅助字符的话就返回true;对于isSupplementaryCodePoint(int),则是在前者的基础上,只有该代码单元是该字符的第一个代码单元时才返回true。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注