Results 1 to 3 of 3
  1. #1
    arvin is offline Member
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default replace non alphabetic letters

    Hi Guys(and girls?)!

    I am trying to replace non alphabetic letter with the right letter(i.e $ == s, @ === a).

    The body of the method:

    Java Code:
    Pattern	p = Pattern.compile("[^a-zA-Z\\s]");
    		Matcher	m = p.matcher(string);
    		
    		if(m.find()){
                         string.replaceAll("[$]","s");
                         string.replaceAll("[@]","a");
                         string.replaceAll("[5]","s");
                         string.replaceAll("[|]","i");
                         //And so on
                    }
    Most of the strings that are sent to this method will probably not have any non-alphabetic letters and that is why i decided to code it like this. So if there is no match, then it wont be neccesary to go through all the code in the if-statement, which will save a lot of time and resources.

    The problem is how i should code the body of the if-statement. Should i just hard code it like this for like 50 different non alphabetic letters(maybe more)? The problem is that what if there is only one non-alphabetic letter that needs to be replaced, then i will use a lot of unnecessary reasourcers. It might be millions of differents strings so it needs to be fast and efficient.

    Some help would be much appreciated.

    Regards
    Arvin
    Last edited by arvin; 10-31-2012 at 02:46 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,941
    Rep Power
    8

    Default Re: replace non alphabetic letters

    Why even bother with the if statement at all?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    arvin is offline Member
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default Re: replace non alphabetic letters

    Because i don't want to go through the instructions if it aint neccesary.

Similar Threads

  1. Convert English letters to Tamil letters
    By srinivasmallabathula in forum New To Java
    Replies: 1
    Last Post: 10-20-2012, 02:39 PM
  2. How to disallow letters?
    By Reeling in forum New To Java
    Replies: 5
    Last Post: 02-17-2012, 12:26 AM
  3. What does the letters mean?
    By mustachMan in forum New To Java
    Replies: 3
    Last Post: 02-11-2010, 09:50 PM
  4. Search string for non-alphabetic characters
    By turnergirl24 in forum New To Java
    Replies: 5
    Last Post: 10-16-2009, 02:02 AM
  5. Letter with Letters
    By elgatoboricua in forum New To Java
    Replies: 7
    Last Post: 09-16-2008, 02:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •