Java Character offsetByCodePoints()方法

java.lang.Character.offsetByCodePoints(CharSequence seq, int index, int codePointOffset) 返回给定的字符序列,该序列是从给定的索引由codePointOffset代码点偏移中的索引。

通过索引和codePointOffset给定的文本范围内未配对的代理算作为每一个代码点。

1 语法

public static int offsetByCodePoints(CharSequence seq, int index, int codePointOffset)

2 参数

seq:该字符序列

index:索引被抵消

codePointOffset:偏移中的代码点

3 返回值

此方法返回的字符序列中的索引

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java Character offsetByCodePoints()方法
 */
import java.lang.*;

public class CharacterDemo {

   public static void main(String[] args) {

      // create a CharSequence seq and assign value
      CharSequence seq = "Hello World";

      // create an int primitive res
      int res;

      // assign result of offsetByCodePoints on seq to res
      res = Character.offsetByCodePoints(seq, 3, 8);

      String str = "The index within the char sequence seq is " + res;

      // print res value
      System.out.println( str );
   }
}

输出结果为:

The index within the char sequence seq is 11

 

热门文章

优秀文章