常量特殊字符? [英] Constants for special characters?

查看:199
本文介绍了常量特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有提供了经常使用的分隔符字符(如,;)的常量,类似于 StringUtils.SPACE/EMPTY/任何公共库LF / CR

Is there any common library that provides constants for often used delimiter chars (like ,;"), similar to StringUtils.SPACE/EMPTY/LF/CR?

推荐答案

有名字,但不是为常数。

There are names but not as constants.

    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

这是繁琐与常量的工作,所以我不认为有人做出的努力。

It is cumbersome working with constants, so I do not think someone made the effort.

您可以自己做,可能产生利用上述Character.getName的枚举,在名称用下划线代替空白。

You could do it yourself, maybe generating the enum using the Character.getName from above, replacing blank in the name with an underscore.

enum Chars {
    COMMA(','),
    SEMICOLON(';'),
    EXCLAMATION_SIGN('!');

    private final int ch;
    private static Map<Integer, Chars> map = new HashMap<>();
    static {
        for (Chars c : Chars.values()) {
            map.put(c.ch, c);
        }
    }

    private Chars(int ch) { this.ch = ch; }

    public int toCodePoint() { return ch; }

    public static Chars fromCodePoint(int cp) {
        return map.get(cp);
    }

    @Override
    public String toString() { return new String(new int[]{ ch }, 0, 1); }
}

心中,还有一个枚举有一个名字吸气剂也为逗号等。

Mind, there an enum has a name getter too, for "COMMA" etc.

这篇关于常量特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆