📜  Java中的 Bidi getLevelAt() 方法及示例

📅  最后修改于: 2022-05-13 01:55:23.112000             🧑  作者: Mango

Java中的 Bidi getLevelAt() 方法及示例

Java.text.Bidi类的getLevelAt()方法用于提供在bidi 文本行的特定点处存在的特定字符的解析级别。

句法:

public int getLevelAt(int offset)

参数:此方法获取需要解析级别的文本行中存在的字符的偏移量。

返回值:此方法为特定字符提供解析级别,如果偏移量小于零或大于双向文本的整个长度,则其偏移量作为参数给出,而不是仅返回等效的基本级别。

下面是说明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-