PDA

View Full Version : StringBuffer help


ole90
11-24-2008, 02:20 PM
So i'm supposed to take a string and input it into a stringbuffer function. I was told to split the string up using stringbuffer but how do i go about doing this? I need to get each individual word in the string and then put that word into a function in order to change that individual word.

Any ideas on how to use stringbuffer to get each different word?

I tried putting the string into an array and using split but apparently I am supposed to use stringbuffer to get the juice.

Any help is appriciated :)

Fou-Lu
11-24-2008, 03:46 PM
Are you sure its a string buffer you want? I'm thinking you want to tokenize you're string, or use a matcher on it. String buffer isn't all that great at finding things, but it is good for slicing and replacing...

StringTokenizer defaults its deliminter on a whitespace, so thats probably what you want to use. Combine that with a string builder and you can replace and append what you're looking to do.

Oh yes, stringTokenizer class is here (http://java.sun.com/j2se/1.5.0/docs/api/java/util/StringTokenizer.html)

DELOCH
11-25-2008, 03:19 AM
It is possible to do...


String[] splitted;
String a = "All your base are belong to us";
splitted = a.split(" "); // function: String.split(regex) returns String[]