Results 1 to 3 of 3
Thread: replace non alphabetic letters
- 10-31-2012, 02:37 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
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:
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.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 }
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
ArvinLast edited by arvin; 10-31-2012 at 02:46 PM.
- 10-31-2012, 02:42 PM #2
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!
- 10-31-2012, 02:55 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Convert English letters to Tamil letters
By srinivasmallabathula in forum New To JavaReplies: 1Last Post: 10-20-2012, 02:39 PM -
How to disallow letters?
By Reeling in forum New To JavaReplies: 5Last Post: 02-17-2012, 12:26 AM -
What does the letters mean?
By mustachMan in forum New To JavaReplies: 3Last Post: 02-11-2010, 09:50 PM -
Search string for non-alphabetic characters
By turnergirl24 in forum New To JavaReplies: 5Last Post: 10-16-2009, 02:02 AM -
Letter with Letters
By elgatoboricua in forum New To JavaReplies: 7Last Post: 09-16-2008, 02:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks