字符串unicode

在Java中,如何确定字符串中的Unicode代码点?

此示例显示如何使用codePointBefore()方法在指定的索引之前返回字符(Unicode代码点)。

package com.zaixian;

public class StringUniCode {
    public static void main(String[] args) {
        String test_string = "Welcome to xuhuhu.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 xuhuhu.com
Unicode code point at position 5 in the string is = 98

上一篇: Java字符串 下一篇: Java数组