StringBuffer.offsetByCodePoints() 方法
描述
java.lang.StringBuffer.offsetByCodePoints() 方法返回此序列中的 index,它从给定索引偏移 codePointOffset 个代码点。
声明
以下是 java.lang.StringBuffer.offsetByCodePoints() 方法的声明。
public int offsetByCodePoints(int index, int codePointOffset)
参数
index − 这是要偏移的索引。
codePointOffset − 这是代码点的偏移量。
返回值
此方法返回此序列中的索引。
异常
NA
示例
下面的例子展示了 java.lang.StringBuffer.offsetByCodePoints() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer("aawxyzaa");
System.out.println("buffer = " + buff);
// returns the index within this sequence
int retval = buff.offsetByCodePoints(1, 4);
// prints the index
System.out.println("index = " + retval);
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
buffer = aawxyzaa index = 5

