• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Efficient text manipulation...

 
Tomer Gal
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 724
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use StringTokenizer or split() method.
 
Joel McNary
Bartender
Posts: 1824
Eclipse IDE Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
David Harkness
Ranch Hand
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic