Results 1 to 13 of 13
Thread: replace string, what is faster
- 03-01-2011, 07:41 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 22
- Rep Power
- 0
- 03-01-2011, 07:43 PM #2
Premature optimization makes kittens cry.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 03-01-2011, 08:09 PM #3
Senior Member
- Join Date
- Feb 2011
- Posts
- 118
- Rep Power
- 0
- 03-02-2011, 01:23 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 22
- Rep Power
- 0
- 03-02-2011, 01:50 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you don't want to bother with StringBuffer you can use org.apache.commons.lang.StringUtils
- 03-02-2011, 01:51 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
And also you can use regular expression to match the replacement.
- 03-02-2011, 02:01 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
replaceAll() is using a regex. You could try replace() since no regex is involved in the example you gave.
An illustration of the problem would be good. For instance showing the slowness to be with the replace operation rather than IO.
- 03-02-2011, 02:14 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Something like this.
Java Code:String.replaceAll("it(?! this)", "it is ball")
- 03-02-2011, 08:46 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
- 03-02-2011, 08:58 AM #10
the problem is not the method replaceAll but using a string when other types are more appropriate, in this case the appropriate type could be a StringBuffer.
- 03-02-2011, 09:13 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
That's true. But OP asking more relevant to the replaceAll() method, is there any alternatives to use, isn't it ...
- 03-02-2011, 09:49 AM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
But there's nothing to indicate a StringBuffer would help is there?
We don't know what the OP is doing with the transformed text yet...
- 03-02-2011, 09:57 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I agreed with you. And that's why I suggest to give a try with direct regex in replaceAll().
Similar Threads
-
Replace String
By Raeghin in forum New To JavaReplies: 1Last Post: 07-28-2009, 03:58 PM -
replace a string using Text i/o
By PureAwesomeness in forum New To JavaReplies: 9Last Post: 07-06-2009, 02:38 AM -
string replace problem
By soni in forum Advanced JavaReplies: 8Last Post: 07-06-2008, 01:21 AM -
Find and replace ( in a String
By hamish10101 in forum New To JavaReplies: 6Last Post: 01-17-2008, 05:51 AM -
String replace method
By venkata.tarigopula in forum Advanced JavaReplies: 1Last Post: 07-10-2007, 08:14 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks