首页 新闻 会员 周边

String类的offsetByCodePoints()

0
悬赏园豆:10 [待解决问题]

String类的offsetByCodePoints(), 这个方法具体是干啥的,有什么使用场景,有什么存在的意义。哪位大佬用大白话解释下,最好解释使用场景和实例。感谢了。

zeronexyz的主页 zeronexyz | 初学一级 | 园豆:186
提问于:2021-07-30 22:22
< >
分享
所有回答(1)
0

进入String源码,里面有你要的一切。
再配合 https://translate.google.cn/ 使用。

/**
 * Returns the index within this {@code String} that is
 * offset from the given {@code index} by
 * {@code codePointOffset} code points. Unpaired surrogates
 * within the text range given by {@code index} and
 * {@code codePointOffset} count as one code point each.
 *
 * @param index the index to be offset
 * @param codePointOffset the offset in code points
 * @return the index within this {@code String}
 * @throws    IndexOutOfBoundsException if {@code index}
 *   is negative or larger then the length of this
 *   {@code String}, or if {@code codePointOffset} is positive
 *   and the substring starting with {@code index} has fewer
 *   than {@code codePointOffset} code points,
 *   or if {@code codePointOffset} is negative and the substring
 *   before {@code index} has fewer than the absolute value
 *   of {@code codePointOffset} code points.
 * @since 1.5
 */
public int offsetByCodePoints(int index, int codePointOffset) {
    if (index < 0 || index > length()) {
        throw new IndexOutOfBoundsException();
    }
    return Character.offsetByCodePoints(this, index, codePointOffset);
}
快乐的凡人721 | 园豆:3916 (老鸟四级) | 2021-08-02 13:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册