如何使用 Java 确定字符串中的 Unicode 代码点
问题描述
如何确定字符串中的 Unicode 代码点?
解决方案
此示例向您展示如何使用 codePointBefore() 方法返回指定索引之前的字符(Unicode 代码点)。
public class StringUniCode {
public static void main(String[] args) {
String test_string = "Welcome to TutorialsPoint";
System.out.println("String under test is = "+test_string);
System.out.println("Unicode code point at"
+" position 5 in the string is = "
+ test_string.codePointBefore(5));
}
}
结果
上述代码示例将产生以下结果。
String under test is = Welcome to TutorialsPoint Unicode code point at position 5 in the string is =111
java_strings.html

