Possible Duplicate:
JAVA: check a string if there is a special character in it
I'm testing a method that transforms a string into another string except it preservers all special characters (non alpha-numeric).
So I'm looking to test the output of this method to ensure it actually preserves these characters.
I know this calls for use of Pattern
and Matcher
classes but not sure how.
I think I need to build a format template, compile it with Pattern
and then use it with Matcher
with the output string of my test method
.
So I'll build the format template character by character. For digits and characters, I can use IsLetter and IsDigit of Character class and insert "\\d"
for digit in my template.
Not sure what I should use for letters and special characters.
Any Ideas?
Thanks.