目录

int offsetByCodePoints(int index, int codePointOffset)

描述 (Description)

java.lang.StringBuilder.offsetByCodePoints()方法返回此序列中的index ,该索引通过codePointOffset代码点从给定索引偏移。

声明 (Declaration)

以下是java.lang.StringBuilder.offsetByCodePoints()方法的声明

public int offsetByCodePoints(int index, int codePointOffset)

参数 (Parameters)

  • index - 这是要偏移的索引。

  • codePointOffset - 这是代码点中的偏移量。

返回值 (Return Value)

此方法返回此序列中的索引。

异常 (Exception)

IndexOutOfBoundsException - 如果index为负或大于此序列的长度,或者如果codePointOffset为正且从index开始的子序列少于codePointOffset代码点,或者如果codePointOffset为负且index之前的子序列小于绝对值codePointOffset代码点。

例子 (Example)

以下示例显示了java.lang.StringBuilder.offsetByCodePoints()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018