Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do i check for special characters  RSS feed

 
Anil Verghese
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How do i check whether a string has special characters or not


Anil
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More of a beginners' question.
What do you mean by special characters?
Suggest you split the String into a char[] array and use the methods of the Character class on the individual chars.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The character-by-character approach will work.

An alternative would be to use a regular expression, via java.util.regex.Pattern. If you look up the API doc for Pattern, you will see that there are a wide variety of character classes on which you can match.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!