DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2002

    Removing special characters from String

    Hi all,

    I am trying to write a method or statement that will remove any special characters from a String before processing it further.

    For example: "Hello my name isn't John" would be changed to "Hello my name isnt John".

    I am then tokenizing the String and placing each char of each token into an ArrayList like so, (casting to Character first):


    I know I could ckeck each Character against a list of special characters like this:

    if(Arraylist[i].equals(') || Arraylist[i].equals(!) || and on and on and on....)

    then break without inserting the character into the Array. It seems like this is a very inefficient way to code this.

    Isn't there some way to compare the ASCII code of each character and say something like:

    if((ASCII_VALUE) of Arraylist[i] > someASCIIVal)

    Then break without adding to Array.
    "I hope that one day I will be able to answer someone elses questions!"

  2. #2
    Join Date
    Oct 2002

    Try RTFM!

    Guess I should have done a little bit more research on this one before posting. Character has a method called isLetter() that returns a boolean. Don't I feel dumb!

    Doesn't get much easier than this. Sorry for wasting everyones time. Darn newbies!!

    Suprised somebody didn't flame me in the time it took me to look it up!! But I guess that would be the java.sun forums ;-)
    "I hope that one day I will be able to answer someone elses questions!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.