Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing strings

Status
Not open for further replies.

MultipartRequest

Programmer
Sep 12, 2001
19
CL
if i have a string with line breaks (carriege return), how can i detect where the line breaks are while i parse the string?
 
One easy way is to use the readline() method in RandomAccessFile. Here is the description from Javadocs:
Code:
Reads the next line of text from this file. This method successively reads bytes from the file, starting at the current file pointer, until it reaches a line terminator or the end of the file. Each byte is converted into a character by taking the byte's value for the lower eight bits of the character and setting the high eight bits of the character to zero. This method does not, therefore, support the full Unicode character set. 

A line of text is terminated by a carriage-return character ('\r'), a newline character ('\n'), a carriage-return character immediately followed by a newline character, or the end of the file. Line-terminating characters are discarded and are not included as part of the string returned. 

This method blocks until a newline character is read, a carriage return and the byte following it are read (to see if it is a newline), the end of the file is reached, or an exception is thrown.
By using this method you know that you are getting everything until the next linebreak. I find it easier than searching for the break character. Just my opinion though.
Wushutwist
 
the problem is that there is no file, the problem is that is an xml file, so in an element i have a huge text split by line breaks. So i parse the xml document and extract the text and place it on a string. now i have to detect the line breaks, after i read the file, not during.
thanksl.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top