• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to differntiate special characters and normal characters

 
sandy bol
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi All
i have a string object suppose
String s="abcdecf%ass$ASDFF"
so how could i replace the special character in the above string with 'X'

Please help out on this
 
Paul Clapham
Sheriff
Posts: 20983
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't have a definition for "special characters". So, you'll have to identify which of those characters you consider to be "special".
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Java does have a class called Character with all sorts of methods to identify different types of character.
 
sandy bol
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there anyway to tracing special characters by ASCII code
 
Paul Clapham
Sheriff
Posts: 20983
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, you're the one who has to say what is "special" in your requirements.
 
B. Bent
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All characters have ascii code (including "special"), so you could you use them if you like, but I'm not sure why.
Maybe you could put all yours "special" character in one array, and then compare every member of array with every character of your string.
Or maybe combined method isLetter() and isDigit() of Character class (if you want only letters and digits).
 
sandy bol
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks B.Bent
i succeeded in my task by using Character class
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic