1

Is there an equivalent Java function that the same as the C99 Standard function 'ispunct()'?

http://linux.die.net/man/3/ispunct

The functions returns true if and only if the character is a punctuation mark.

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Frank-Rene Schäfer
  • 3,182
  • 27
  • 51

2 Answers2

9

You could use

if (Character.toString(myChar).matches("\\p{Punct}")) {
Reimeus
  • 158,255
  • 15
  • 216
  • 276
4

Try this (from this link):

public static 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;
}
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292