java.lang.Character.getName()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(337)

本文整理了Java中java.lang.Character.getName()方法的一些代码示例,展示了Character.getName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.getName()方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:getName

Character.getName介绍

[英]Returns a human-readable name for the given code point, or null if the code point is unassigned.

As a fallback mechanism this method returns strings consisting of the Unicode block name (with underscores replaced by spaces), a single space, and the uppercase hex value of the code point, using as few digits as necessary.

Examples:

  • Character.getName(0) returns "NULL".
  • Character.getName('e') returns "LATIN SMALL LETTER E".
  • Character.getName('\u0666') returns "ARABIC-INDIC DIGIT SIX".
  • Character.getName(0xe000) returns "PRIVATE USE AREA E000".

Note that the exact strings returned will vary from release to release.
[中]返回给定代码点的可读名称,如果未指定代码点,则返回null。
作为一种回退机制,此方法返回由Unicode块名(下划线替换为空格)、单个空格和代码点的大写十六进制值组成的字符串,并根据需要使用少量数字。
示例:
*性格。getName(0)返回“NULL”。
*性格。getName('e')返回“拉丁文小写字母e”。
*性格。getName('\u0666')返回“阿拉伯-印度数字六”。
*性格。getName(0xe000)返回“私有使用区域E000”。
请注意,返回的确切字符串因版本而异。

代码示例

代码示例来源:origin: stackoverflow.com

String VIETNAMESE_DIACRITIC_CHARACTERS = "ẮẰẲẴẶĂẤẦẨẪẬÂÁÀÃẢẠĐẾỀỂỄỆÊÉÈẺẼẸÍÌỈĨỊỐỒỔỖỘÔỚỜỞỠỢƠÓÒÕỎỌỨỪỬỮỰƯÚÙỦŨỤÝỲỶỸỴ";

for (char c: VIETNAMESE_DIACRITIC_CHARACTERS.toCharArray()) {
  System.out.println(c + ": " + Character.getName(c));
}

代码示例来源:origin: KokaKiwi/MCLauncher

public String render(CharSequence str)
{
  String s = "";
  
  for (int i = str.length() - 2; i < str.length(); i++)
  {
    final char c = str.charAt(i);
    s += Character.getName(c);
  }
  
  return s;
}

代码示例来源:origin: stackoverflow.com

for (int cp = 32; cp < 48; ++cp) {
    System.out.printf("%c : %s%n", cp, Character.getName(cp));
  }

 : SPACE
! : EXCLAMATION MARK
" : QUOTATION MARK
# : NUMBER SIGN
$ : DOLLAR SIGN
% : PERCENT SIGN
& : AMPERSAND
' : APOSTROPHE
( : LEFT PARENTHESIS
) : RIGHT PARENTHESIS
* : ASTERISK
+ : PLUS SIGN
, : COMMA
- : HYPHEN-MINUS
. : FULL STOP
/ : SOLIDUS

代码示例来源:origin: stackoverflow.com

void dump(String s) {
  int n = 0;
  for (int i = 0; i < s.length(); ++n) {
    int cp = s.codePointAt(i);
    int bytes = Character.charCount(cp);
    i += bytes;
    System.out.printf("[%d] #%dB: U+%X = %s%n",
      n, bytes, cp, Character.getName(cp));
  }
  System.out.printf("Length:%d%n", n);
}

代码示例来源:origin: stackoverflow.com

String s = "१२३";
for (int i = 0; i < s.length(); i++) {
  char c = s.charAt(i);
  System.out.printf("%s is digit %s%n", Character.getName(c), Character.isDigit(c));
}

代码示例来源:origin: stackoverflow.com

int[] codePoints = { 0x03F3, 0x006A}; 
for (int codePoint : codePoints) {
  char lowerCase = (char) Character.toLowerCase(codePoint);
  char upperCase = (char) Character.toUpperCase(codePoint);
  System.out.printf("Unicode name: %s%n", Character.getName(codePoint));
  System.out.printf("lowercase   : %s%n", lowerCase);
  System.out.printf("uppercase   : %s (%s)%n", upperCase,
    Character.isUpperCase(upperCase));
}

代码示例来源:origin: stackoverflow.com

String str = "ิ"; // \u0E34
System.out.println("character length: " + str.length());

System.out.print("bytes: ");
for (byte b : str.getBytes("UTF-8")) {
  System.out.append(Integer.toHexString(b & 0xFF).toUpperCase() + " ");
}
System.out.println("");

int codePoint = Character.codePointAt(str, 0);
System.out.println("unicode name of the codepoint: " + Character.getName(codePoint));

代码示例来源:origin: org.github.evenjn/codecs

public static String aboutCodepoint( Integer cp ) {
  StringBuilder sb = new StringBuilder( );
  char[] chars = Character.toChars( cp );
  sb.append( asUnicodeHex( cp ) );
  sb.append( " " ).append( chars );
  sb.append( " " ).append( Character.getName( cp ) );
  return sb.toString( );
}

代码示例来源:origin: stackoverflow.com

for (int codePoint = 0x600; codePoint < 0x900; ++codePoint) {
  if (Character.isAlphabetic(codePoint)
      && UnicodeScript.of(codePoint) == UnicodeScript.ARABIC) {

    System.out.printf("\u200E\\%04X \u200F%s\u200E %s%n",
        codePoint,
        new String(Character.toChars(codePoint)),
        Character.getName(codePoint));
  }
}

代码示例来源:origin: org.github.evenjn/plaintext

public static String aboutCodepoint( Integer cp ) {
  StringBuilder sb = new StringBuilder( );
  char[] chars = Character.toChars( cp );
  sb.append( asUnicodeHex( cp ) );
  sb.append( " " ).append( chars );
  sb.append( " " ).append( Character.getName( cp ) );
  return sb.toString( );
}

代码示例来源:origin: stackoverflow.com

import java.nio.charset.StandardCharsets;

public class Dashes {

  public static void main(String[] args) {
    // see: https://en.wikipedia.org/wiki/Dash
    byte[] enDash = {-30, -128, -109};
    byte[] minusSign = {45};
    byte[] emDash = {-30, -128, -108};

    byte[][] charBytes = new byte[3][];
    charBytes[0] = enDash;
    charBytes[1] = minusSign;
    charBytes[2] = emDash;

    for (byte[] bytes : charBytes) {
      String s = new String(bytes, StandardCharsets.UTF_8);
      char c = s.charAt(0);
      System.out.printf("%d  %s  %s%n", s.length(), c, Character.getName(c));
    }
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  // Creators
  World worldMap = new World(mapWidth, mapHeight);
  Character john = new Character("John", 0, 0);
  Character mary = new Character("Mary", 1, 4);
  worldMap.add(john);
  worldMap.add(mary);

  for (int x = 0; x < mapWidth; x++) {
    worldMap.setTileType(x, 5, "forest");
  }

  // Printing out info about character(s)
  //I think the world map should  have a list of characters.

  for (Character character : charList) {
    System.out.print(character+": " + character.getName() + "\n");
  }
  System.out.print("\n"+charList.size() + " characters in play\n\n");
  List<Tile> tileList = worldMap.getTiles(); 
  // Printing out info about tile(s)
  for (Tile tile : tileList) {
    System.out.print(tile + " type: " + tile.getType() + "\n");
  }
  System.out.print("\n"+tileList.size() + " tiles in play");
}

代码示例来源:origin: org.opendaylight.mdsal/mdsal-binding2-generator-util

/**
 * Converting first char of identifier. This happen only if this char is
 * non-java char.
 *
 * @param firstChar
 *            - first char
 * @param existNext
 *            - existing of next char behind actual char
 * @return converted char
 */
private static String convertFirst(final char firstChar, final boolean existNext) {
  final String name = DASH_OR_SPACE_MATCHER.replaceFrom(Character.getName(firstChar), UNDERSCORE);
  return existNext ? name + '_' : name;
}

代码示例来源:origin: stackoverflow.com

public class CharacterMapAssert extends AbstractMapAssert<MapAssert<Character, Integer>, Map<Character, Integer>, Character, Integer> {

  public CharacterMapAssert(Map<Character, Integer> actual) {
    super(actual, CharacterMapAssert.class);
  }

  public static CharacterMapAssert assertThat(Map<Character, Integer> actual) {
    return new CharacterMapAssert(actual);
  }

  public CharacterMapAssert hasNameWithAge(String name, int age) {
    isNotNull();

    for (Map.Entry<Character, Integer> entrySet : actual.entrySet()) {
      if (entrySet.getKey().getName().contains(name) && (int) entrySet.getValue() == age) {
        return this;
      }
    }

    String msg = String.format("entry with name %s and age %s does not exist", name, age);
    throw new AssertionError(msg);
  }

}

代码示例来源:origin: stackoverflow.com

jasonString.toCodePoints()
    .filter(cp -> cp >= 256)
    .forEach(cp -> {
      System.out.printf("U+%X = %s%n",
        cp, Character.getName(cp));
     });

boolean containsEmoji(String s) {
  return s.codePoints().anyMatch(cp ->
    UnicodeBlock.of(cp).equals(UnicodeBlock.EMOTICONS));
}

代码示例来源:origin: stackoverflow.com

System.out.print(c.getName());

代码示例来源:origin: stackoverflow.com

name.setText(c.getName());

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws UnsupportedEncodingException
{
  Random random = new Random();

  byte bytes[] = new byte[16];
  random.nextBytes(bytes);
  printBytes(bytes);

  final String s = new String(bytes, "UTF-8");
  System.out.println(s);
  printCharacters(s);
}

private static void printBytes(byte[] bytes)
{
  for (byte aByte : bytes)
  {
    System.out.print(
        Integer.toHexString(Byte.toUnsignedInt(aByte)) + " ");
  }
  System.out.println();
}

private static void printCharacters(String s)
{
  s.codePoints().forEach(i -> System.out.println(Character.getName(i)));
}

代码示例来源:origin: org.ceylon-lang/com.redhat.ceylon.typechecker

codePoint<=0xE01EF; 
  codePoint++) {
String cn = Character.getName(codePoint);
if (cn!=null && cn.equals(name)) {
  String unicodeChar =

代码示例来源:origin: org.kopitubruk.util/JSONUtil

fmt = mfmt;
message.append(String.format(fmt, badCodePoint, Character.getName(badCodePoint)));

相关文章

Character类方法