This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Efficient text manipulation... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Efficient text manipulation..." Watch "Efficient text manipulation..." New topic
Author

Efficient text manipulation...

Tomer Gal
Greenhorn

Joined: Dec 18, 2004
Posts: 24
If I got a String or a StringBuffer for example :
StringBuffer s = new StringBuffer();

s = "Hello World! Whats up?";

What is an efficient way to get the 1st word ("Hello") - save it and then to cut it from the string so all that is left is : " World! Whats up?"

Thanks for the help in advanced guys
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Use StringTokenizer or split() method.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
Depends on how the splitting si to be acheived -- the split() could be very annoying. If we assume that words are separated by spaces, then a simple indexOf(' ') and then substring would work nicely:



Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
My take was that the main question was how to remove "Hello" .. not just get that string.StringBuffer.delete() will result in an array copy to shift the text after the removed portion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Efficient text manipulation...
 
Similar Threads
Q on casting
Which one of these two programs execute fast
Final & Immutable class
String and StringBuffer
Help in Strings