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 getNumericValue()用法及代碼示例
- Java Character getType()用法及代碼示例
- Java Character getType(char ch)用法及代碼示例
- Java Character getDirectionality()用法及代碼示例
- Java Character isLetter()用法及代碼示例
- Java Character isAlphabetic()用法及代碼示例
- Java Character isValidCodePoint()用法及代碼示例
- Java Character codePointCount()用法及代碼示例
- Java Character isISOControl()用法及代碼示例
- Java Character isSpace()用法及代碼示例
- Java Character toTitleCase()用法及代碼示例
- Java Character isMirrored()用法及代碼示例
- Java Character isBmpCodePoint()用法及代碼示例
- Java Character toUpperCase()用法及代碼示例
- Java Character isIdentifierIgnorable()用法及代碼示例
- Java Character isDigit()用法及代碼示例
- Java Character digit()用法及代碼示例
- Java Character toChars()用法及代碼示例
- Java Character compare()用法及代碼示例
- Java Character isLowerCase()用法及代碼示例
注:本文由純淨天空篩選整理自 Java Character getName() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。