请问各位牛牛们,  String类的codePointCount()和 offsetBycodePoints()方法,一般都用在什么情况下啊 ?  真不知道这俩家伙是为了干啥而存在的 ?。  给个简单的说明,如果有例子就更好了

解决方案 »

  1.   

    codePointCount
    public int codePointCount(int beginIndex,
                              int endIndex)返回此 String 的指定文本范围中的 Unicode 代码点数。文本范围始于指定的 beginIndex,一直到索引 endIndex - 1 处的 char。因此,该文本范围的长度(用 char 表示)是 endIndex-beginIndex。该文本范围内每个未配对的代理项计为一个代码点。 参数:
    beginIndex - 文本范围的第一个 char 的索引。
    endIndex - 文本范围的最后一个 char 之后的索引。 
    返回:
    指定文本范围中 Unicode 代码点的数量 
    抛出: 
    IndexOutOfBoundsException - 如果 beginIndex 为负,或 endIndex 大于此 String 的长度,或 beginIndex 大于 endIndex。
    从以下版本开始: 
    1.5 offsetByCodePoints
    public int offsetByCodePoints(int index,
                                  int codePointOffset)返回此 String 中从给定的 index 处偏移 codePointOffset 个代码点的索引。文本范围内由 index 和 codePointOffset 给定的未配对代理项各计为一个代码点。 参数:
    index - 要偏移的索引
    codePointOffset - 代码点中的偏移量 
    返回:
    String 的索引 
    抛出: 
    IndexOutOfBoundsException - 如果 index 为负或大于此 String 的长度;或者 codePointOffset 为正,且以 index 开头子字符串的代码点比 codePointOffset 少;如果 codePointOffset 为负,且 index 前面子字符串的代码点比 codePointOffset 的绝对值少。
    从以下版本开始: 
    1.5 
      

  2.   

    那个代码点是指这个字符在unicode中的字节数,也就是一个字符的字节数。