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