當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。