Programming Tips - Java: Write an ispunct() in Java

Date: 2012may23 Language: Java Q. Java: Write an ispunct() in Java A. Here's one way:
boolean isPunct(final char c) { final int val = (int)c; return val >= 33 && val <= 47 || val >= 58 && val <= 64 || val >= 91 && val <= 96 || val >= 123 && val <= 126; // We could use Character.getType() but I don't really trust it. // This is simple and works for ASCII values. // Of course this does not work work for international characters. }
Since ASCII isn't going to change it doesn't seem so hard to use hardcode number. More info http://man-ascii.com