Java String codePointCount() 方法
实例
返回在字符串中找到的 Unicode 值的数目:
public class Main {public static void main(String[] args) {String myStr = "Hello";int result = myStr.codePointCount(0, 5);System.out.println(result);}}
定义与用法
codePointCount() 方法返回在字符串中找到的 Unicode 值的数量。
使用 startIndex 和 endIndex 参数指定搜索的开始和结束位置。
第一个字符的索引为 0,第二个字符的索引为 1,依此类推。
语法
参数值
| 参数 | 描述 |
|---|---|
| startIndex | 一个 int 值,表示字符串中第一个字符的索引 |
| endIndex | 一个 int 值,表示字符串中最后一个字符后的索引 |
技术细节
| 返回: | 一个 int 值,表示在字符串中找到的 Unicode 值的数量 |
|---|---|
| 异常: | IndexOutOfBoundsException -如果 startIndex 为负数,或 endindex 大于字符串长度,或startIndex大于endindex |
| Java 版本: | 1.5 |