You could do something like this:
private enum SpecialChars{
COMMA(","),
APOSTROPHE("'"),
OPEN_PAREN("("),
CLOSE_PAREN(")");
private String value;
private SpecialChars(String value)
{
this.value = value;
}
public String toString()
{
return this.value; //will return , or ' instead of COMMA or APOSTROPHE
}
}
Example use:
public static void main(String[] args)
{
String line = //..read a line from STDIN
//check for special characters
if(line.equals(SpecialChars.COMMA)
|| line.equals(SpecialChars.APOSTROPHE)
|| line.equals(SpecialChars.OPEN_PAREN)
|| line.equals(SpecialChars.CLOSE_PAREN)
) {
//do something for the special chars
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…