当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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-



相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Bidi getLevelAt() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。