Java String codePointBefore() 方法
示例
返回字串中第一個字元的 Unicode 值("H" 的 Unicode 值為 72)
String myStr = "Hello";
int result = myStr.codePointBefore(1);
System.out.println(result);
定義和用法
codePointBefore()
方法返回字串中指定索引前一個字元的 Unicode 值。
第一個字元的索引是 1,第二個字元是 2,依此類推。
注意:值 0 將產生錯誤,因為這是一個負數(超出範圍)。
語法
public int codePointBefore(int index)
引數值
引數 | 描述 |
---|---|
index | 一個 int 值,表示要返回的 Unicode 值後面的索引。 |
技術詳情
返回 | 一個 int 值,表示指定索引前的 Unicode 值。 |
---|---|
丟擲 | IndexOutOfBoundsException - 如果索引為負數或不小於指定字串的長度。 |
Java 版本 | 1.5 |
❮ String Methods