This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Get a single line from a String Buffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Get a single line from a String Buffer" Watch "Get a single line from a String Buffer" New topic
Author

Get a single line from a String Buffer

Peter Shipway
Ranch Hand

Joined: Mar 25, 2004
Posts: 71
How do i get a single line from a string buffer that has already been created?
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

How do you know the Stringbuffer contains lines at all?
If your buffer looks like this:

text2 seems to be a line, but text1 and text3 could be a part of a line.
For a buffer containing no NewLine at all, would you say the whole buffer is a line on it's own?

So do we have three lines here?:


http://home.arcor.de/hirnstrom/bewerbung
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8834
    
    7

You can read a line from a StringBuffer using Readers:


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
That gets you the first line.

You may need to create the BufferedReader as shown and then call readLine() on it until you get the line you want.


Mike Gershman
SCJP 1.4, SCWCD in process
 
jQuery in Action, 2nd edition
 
subject: Get a single line from a String Buffer
 
Similar Threads
why it is giving errors
Pls Help on read the log file BACKWARd?
OutOfMemoryError: Java heap space error when exporting more than 65MB file
An exception in java-XML --kindly clarify-urgent
java.net.URLConnection example?