java.lang.StringBuffer.codePointBefore()方法範例


java.lang.StringBuffer.codePointBefore() 法指定索引之前,返回字元(Unicode程式碼點)。該索引(Unicode程式碼單元)範圍是1到length()的 char值。

宣告

以下是java.lang.StringBuffer.codePointBefore()方法的宣告

public int codePointBefore(int index)

引數

  • index -- 這是應返回程式碼點的索引。

返回值

此方法返回給定索引之前的Unicode程式碼點值。

異常

  • NA

例子

下面的例子顯示java.lang.StringBuffer.codePointBefore()方法的使用。

package com.yiibai;

import java.lang.*;

public class StringBufferDemo {

  public static void main(String[] args) {
  
    StringBuffer buff = new StringBuffer("TUTORIALS");
    System.out.println("buffer = " + buff);

    // returns the codepoint before index 3
    int retval = buff.codePointBefore(3);
    System.out.println("Character(unicode point) = " + retval);
    
    buff = new StringBuffer("amrood admin ");
    System.out.println("buffer = " + buff);
    // returns the codepoint before index 6
    retval = buff.codePointBefore(6);
    System.out.println("Character(unicode point) = " + retval);
  }
}

讓我們來編譯和執行上面的程式,這將產生以下結果:

buffer = TUTORIALS
Character(unicode point) = 84
buffer = amrood admin
Character(unicode point) = 100