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
  • 11,797
  • 4
  • 29
  • 49
Frank-Rene Schäfer
  • 2,828
  • 22
  • 43

2 Answers2

9

You could use

if (Character.toString(myChar).matches("\\p{Punct}")) {
Reimeus
  • 155,977
  • 14
  • 207
  • 269
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
  • 170,119
  • 31
  • 233
  • 283