File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes StringBuffer Very Urgent please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StringBuffer Very Urgent please" Watch "StringBuffer Very Urgent please" New topic
Author

StringBuffer Very Urgent please

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Hi,
I have defined String Buffer of 2K capacity. Server is send me data withing that capacity of string Buffer. After StringBuffer recieves data from the server on client side, I want to parse it. I have delimeter ":" to parse the stringBuffer?
I tried to use StringTokenizer, Substring. But I can't get it.
Here is my example:
import java.applet.Applet;
import java.util.*;
public class sbDemo extends Applet{
StringBuffer sb;
StringTokenizer st;
public void init(){
sb.append("Anuja:shah:Konica:Business:Technology");
st = new StringTokenizer(sb,":");
while(st.hasMoreTokens()){
System.out.println("The String is --->" + st.nextToken());
}
}
}
Thanks,
Angela
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
Hi Angela
A couple of observations about the code you posted. Firsty, you need to create the StringBuffer object before you try to call the append() method, so do something like:
<code>sb = new StringBuffer();</code> before the call to append().
Also, the constructor to the StringTokenizer takes a String as its first argument, so you need to amend the line where you try to create it to read:
<code>st = new StringTokenizer(sb.toString(),":");</code>
If you still have problems, come back and describe what happens when you attempt to compile and run your code.
Hope this helps
Michael
------------------
"One good thing about music - when it hits, you feel no pain"
Bob Marley


"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Thanks Michael,
It's working!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringBuffer Very Urgent please