java.lang.StringBuffer.codePointCount()%uA0方法在这个序列中的指定文本范围内返回Unicode代码点的数量。文本范围始于指定ꂾginIndex%uA0并延伸到将char在索引%uA0endIndex - 1. 这样的文本范围的长度(以字符)是%uA0endIndex - beginIndex.
声明
以下是java.lang.StringBuffer.codePointCount()方法的声明
public int codePointCount(int beginIndex, int endIndex)
参数
-
beginIndex%uA0-- 这是该索引在文本范围的第一个字符。
-
endIndex%uA0-- 这是文本范围的最后一个字符之后的索引。
返回值
这个方法返回指定的文本范围的Unicode代码点的数量。
异常
-
NA
例子
下面的例子显示java.lang.StringBuffer.codePointCount()方法的使用。
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 count from index 1 to 5 int retval = buff.codePointCount(1, 5) System.out.println("Count = " + retval) buff = new StringBuffer("amrood admin ") System.out.println("buffer = " + buff) // returns the codepoint count from index 3 to 9 retval = buff.codePointCount(3, 9) System.out.println("Count = " + retval) } }
让我们来编译和运行上面的程序,这将产生以下结果:
buffer = TUTORIALS Count = 4 buffer = amrood admin Count = 6