java.lang.StringBuilder.codePointBefore() %uA0方法指定索引之前返回字符(Unicode代码点)。该指数是指范围从1到 length()的char值(Unicode代码单元)。
声明
以下是java.lang.StringBuilder.codePointBefore()方法的声明
public int codePointBefore(int index)
参数
-
index%uA0-- 这是接下来应返回的代码点索引。
返回值
此方法返回给定索引之前的Unicode代码点值。
异常
-
IndexOutOfBoundsException%uA0-- 如果索引参数比该序列的长度大或小于1。
例子
下面的例子显示java.lang.StringBuilder.codePointBefore()方法的使用。
package com.yiibai import java.lang.* public class StringBuilderDemo { public static void main(String[] args) { StringBuilder str = new StringBuilder("programming") System.out.println("string = " + str) // returns the codepoint before index 3 int retval = str.codePointBefore(3) System.out.println("Character(unicode point) = " + retval) str = new StringBuilder("amrood admin ") System.out.println("string = " + str) // returns the codepoint before index 6 retval = str.codePointBefore(6) System.out.println("Character(unicode point) = " + retval) } }
让我们来编译和运行上面的程序,这将产生以下结果:
string = programming Character(unicode point) = 111 string = amrood admin Character(unicode point) = 100