java.lang.StringBuilder.offsetByCodePoints()%uA0方法返回该序列给定的索引,codePointOffset代码点偏移中的索引。
声明
以下是java.lang.StringBuilder.offsetByCodePoints()方法的声明
public int offsetByCodePoints(int index, int codePointOffset)
参数
-
index%uA0-- 这是该索引为偏移量offset。
-
codePointOffset%uA0-- 这是偏移量的代码点。
返回值
此方法返回该序列的索引。
异常
-
IndexOutOfBoundsException%uA0-- 如果索引为负或大于该序列的长度,或如果codePointOffset为正和start索引的子序列比codePointOffset码点小,或者如果codePointOffset是为负和索引之前的子序列比codePointOffset码的绝对值小。
例子
下面的例子显示java.lang.StringBuilder.offsetByCodePoints()方法的使用。
package com.yiibai import java.lang.* public class StringBuilderDemo { public static void main(String[] args) { StringBuilder str = new StringBuilder("abcdefg") System.out.println("string = " + str) // returns the index within this sequence int retval = str.offsetByCodePoints(1, 4) // prints the index System.out.println("index = " + retval) } }
让我们来编译和运行上面的程序,这将产生以下结果:
string = abcdefg index = 5