Dave's Brain

Browse - Programming Tips - How can I write an ispunct() in Java?

Date: 2012may23
Language: Java


Q.  How can I 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 international characters. }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.