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


Java Character getName()用法及代码示例


getName(int codePoint) 方法返回指定字符的 Unicode 名称,如果未分配 codePoint,则返回 null。如果 Unicode 数据文件没有为指定的字符指定名称,则返回的名称与表达式的结果相同。

Character.UnicodeBlock.of(codePoint).toString().replace('-'), '  ')+"  "+Integer.toHexString(codePoint).toUpperCase(Loale.ROOT);

用法

public static string getName(int codePoint)

参数

上述方法只需要一个参数:

代码点:它是字符(Unicode 代码点)

返回值

如果 codePoint 未分配,则为字符或 null。

例子1

public class JavaCharactergetNameExample1 {
    public static void main(String[] args) {
          // Declare the codePoints
             int codepoint = 00;     
          // Get the Unicode name of the specified character codePoint
             String result = Character.getName(codepoint);
         // Print the result
             System.err.println("The first character '" + (char)codepoint + "' has the unicode name as:" + result);
         }
    }

输出:

The first character ' ' has the Unicode name as:NULL 

例子2

public class JavaCharactergetNameExample2 {
    public static void main(String[] args) {
      // Declare the codePoints
         int codepoint1 = 93;
         int codepoint2 = 69;
      // Get the Unicode name of the specified character codePoint
         String result1 = Character.getName(codepoint1);
         String result2 = Character.getName(codepoint2);
     // Print the result
         System.err.println("The character '" + (char)codepoint1 + "' has the unicode name as:" + result1);
         System.err.println("The character '" + (char)codepoint2+ "' has the unicode name as:" + result2);
     }
}

输出:

The character ']' has the unicode name as:RIGHT SQUARE BRACKET
The character 'E' has the unicode name as:LATIN CAPITAL LETTER E

例子3

public class JavaCharactergetNameExample3 {
    public static void main(String[] args) {
      // Declare the codePoints
        int codepoint1 = 80;
        int codepoint2 = 55;
        int codepoint3 = 110;
        int codepoint4 = 780;
     // Get the Unicode name of the specified character codePoint
        String result1 = Character.getName(codepoint1);
        String result2 = Character.getName(codepoint2);
        String result3 = Character.getName(codepoint3);
        String result4 = Character.getName(codepoint4);
       // Print the result
System.err.println("The first character '" + (char)codepoint1 + "' has the unicode name as:" + result1);
System.err.println("The second character '" + (char)codepoint2+ "' has the unicode name as:" + result2);
System.err.println("The third character '" + (char)codepoint3+ "' has the unicode name as:" + result3);
System.err.println("The fourth character '" + (char)codepoint4+ "' has the unicode name as:" + result4);
         }
    }

输出:

The first character 'P' has the unicode name as:LATIN CAPITAL LETTER P
The second character '7' has the unicode name as:DIGIT SEVEN
The third character 'n' has the unicode name as:LATIN SMALL LETTER N
The fourth character '?' has the unicode name as:COMBINING CARON



相关用法


注:本文由纯净天空筛选整理自 Java Character getName() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。