Java StringBuilder codePointBefore()方法

java.lang.StringBuilder.codePointBefore()  方法指定索引之前返回字符(Unicode代码点)。该指数是指范围从1到 length()的char值(Unicode代码单元)。

1 语法

public int codePointBefore(int index)

2 参数

index : 这是接下来应返回的代码点索引。

3 返回值

此方法返回给定索引之前的Unicode代码点值。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java StringBuilder codePointBefore()方法
 */
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

 

热门文章

优秀文章