Character 类的 offsetByCodePoints(char[]a, int start, int count, int index, int codePointOffset) 方法返回给定 char sub-array 内的指定索引,该索引已被 codePointOffset codePoints 偏移。 start 和count 参数指定char 数组的sub-array。位于由索引和 codePointOffset 给出的文本范围内的所有未配对代理项都计为一个 codePoint。
用法
public static boolean offsetByCodePoints(char[]a, int start, int count, int index, int codePointOffset)
参数
上述方法需要五个参数:
- char 类型数组。
- 开始是给定 sub-array 的第一个字符的索引。
- 计数是 sub-array 的总长度。
- 需要偏移的索引。
- codePointOffset 是代码点中的偏移量。
返回值
offsetByCodePoints(char[]a, int start, int count, int index, int codePointOffset) 方法返回子数组内的指定索引。
例子1
public class JavaCharactroffsetByCodePointsExample_1 {
public static void main(String[] args) {
// Create a char array ch and assign the values to char array ch.
char[] ch = new char[] { 'a', 'b', 'c', 'd', 'e', 'f' };
// Create two integer primitives start and count and again assign them the values.
int start = 1;
int count = 5;
// Again create an integer primitive result.
int result;
// Assign the result of offsetByCodePoints on subarray result.
result = Character.offsetByCodePoints(ch, start, count, 2, 4);
String str = "The index within the subarray ch is given as:" + result;
// Print the result.
System.err.println( str );
}
}
输出:
The index within the subarray ch is given as:6
Java 字符 offsetByCodePoints(CharSequence seq, int index, int codePointOffset) 方法
Character 类的 offsetByCodePoints(CharSequence seq, int index, int codePointOffset) 方法返回给定字符序列中的指定索引,该索引从给定索引偏移了 codePointOffset codePoints。
位于由索引和 codePointOffset 给出的文本范围内的所有未配对代理项都计为一个 codePoint。
用法
public static char offsetByCodePoints(CharSequence seq, int index, int codePointOffset)
参数
上述方法需要三个参数:
- 字符序列 seq。
- 需要偏移的索引。
- 代码点偏移量。
返回值
offsetByCodePoints(CharSequence seq, int index, int codePointOffset) 方法返回字符序列中的指定索引。
例子1
public class JavaCharacteroffsetByCodePointsExample_1 {
public static void main(String[] args) {
// Initialize a new CharSequence object.
CharSequence charseq = "This is my first string!";
// Initialize beginIndex and codePointOffset
int Index = 0;
int codePointOffset = charseq.length();
// Get the index within the given char sequence.
int result = Character.offsetByCodePoints(charseq,Index, codePointOffset); System.out.println("The result for the above method can be represented as:" + result);
}
}
输出:
The result for the above method can be represented as:24
相关用法
- Java Character isLetter()用法及代码示例
- Java Character isAlphabetic()用法及代码示例
- Java Character isValidCodePoint()用法及代码示例
- Java Character codePointCount()用法及代码示例
- Java Character isISOControl()用法及代码示例
- Java Character getType()用法及代码示例
- Java Character getNumericValue()用法及代码示例
- Java Character isSpace()用法及代码示例
- Java Character toTitleCase()用法及代码示例
- Java Character isMirrored()用法及代码示例
- Java Character isBmpCodePoint()用法及代码示例
- Java Character toUpperCase()用法及代码示例
- Java Character isIdentifierIgnorable()用法及代码示例
- Java Character isDigit()用法及代码示例
- Java Character digit()用法及代码示例
- Java Character toChars()用法及代码示例
- Java Character compare()用法及代码示例
- Java Character isLowerCase()用法及代码示例
- Java Character isJavaIdentifierPart()用法及代码示例
- Java Character getType(char ch)用法及代码示例
注:本文由纯净天空筛选整理自 Java Character offsetByCodePoints() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。