字串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數組