Java Bidi getLevelAt()方法及实例
java.text.Bidi 类的 getLevelAt() 方法是用来提供bidi文本行中特定点上的特定字符的解析水平。
语法
public int getLevelAt(int offset)
参数 :该方法获取需要解决的级别的文本行中存在的字符的偏移量。
返回值: 该方法为偏移量作为参数的特定字符提供解决的级别,如果偏移量小于零或大于整个bidi文本的长度,那么它只是返回相等的基本级别。下面是说明 getLevelAt() 方法的例子:
例1 :
// Java program to demonstrate
// getLevelAt() method
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
// creating and initializing Bidi
Bidi bidi = new Bidi("Geeks for Geeks", 0);
int offset = 3;
// getting resolved level of Character
// using getLevelAt() method
int status = bidi.getLevelAt(offset);
// display the result
if (offset > 0
&& (bidi.getLength()) > offset)
System.out.println(
"resolved level of the "
+ "Character at offset "
+ offset + " is "
+ status);
else
System.out.println(
"base direction level is "
+ status);
}
}
输出
resolved level of the Character at offset 3 is 0
例2 :
// Java program to demonstrate
// getLevelAt() method
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
// creating and initializing Bidi
Bidi bidi = new Bidi("Tajmahal", 0);
int offset = -3;
// getting resolved level of Character
// using getLevelAt() method
int status = bidi.getLevelAt(offset);
// display the result
if (offset > 0
&& (bidi.getLength()) > offset)
System.out.println(
"resolved level of the "
+ "Character at offset "
+ offset + " is "
+ status);
else
System.out.println(
"base direction level is "
+ status);
}
}
输出
base direction level is 0
参考资料: https://docs.oracle.com/javase/9/docs/api/java/text/Bidi.html#getLevelAt-int-