File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StringBuffer Very Urgent please" Watch "StringBuffer Very Urgent please" New topic

StringBuffer Very Urgent please

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
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(){
st = new StringTokenizer(sb,":");
System.out.println("The String is --->" + st.nextToken());
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
"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!!!
It is sorta covered in the JavaRanch Style Guide.
subject: StringBuffer Very Urgent please
It's not a secret anymore!