• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get a single line from a String Buffer  RSS feed

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i get a single line from a string buffer that has already been created?
 
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?:
 
Bartender
Posts: 9454
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can read a line from a StringBuffer using Readers:
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Everybody's invited. Even this tiny ad:
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!