在Java中,如何确定字符串中的Unicode
代码点?
此示例显示如何使用codePointBefore()
方法在指定的索引之前返回字符(Unicode
代码点)。
package com.yiibai;
public class StringUniCode {
public static void main(String[] args) {
String test_string = "Welcome to Yiibai.com";
System.out.println("String under test is = " + test_string);
System.out.println("Unicode code point at"
+ " position 15 in the string is = "
+ test_string.codePointBefore(15));
}
}
执行上面示例代码,得到以下结果 -
String under test is = Welcome to Yiibai.com
Unicode code point at position 5 in the string is = 98