• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to to recognize new line character?.

 
Deepa Balasubramanayam
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am entering description in a text area in multiple lines. If I strike "enter" key to go to next line.In the program I want to recognize the new line character and replace with <BR>.
How can I find the new line character?.
Thanks
Deepa
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The character or characters used to display a new line do differ among differing platforms.
I seem to recall that, within a text file, Windows will display a new line with two characters - the carriage return character (13) and the form feed new line character (10). I think that UNIX will typically use only the form feed new line character (10). Macs may be something else.
So, you may have to search for a set of characters (in the case of windows) or simply a single character. In any case, it'll probably be easier to search for the new line character sequence as a String. This can be obtained during program execution with:
System.getProperty( "line.separator" );
Regarding what methods to use to actually search within the text area's text for the appropriate character sequence, I recommend that you take a look at The API Documentation for what methods are available to anaylyze Strings and StringBuffers.
Good Luck.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make life easy, see the BufferedReader class. The readLine() method takes care of figuring out where the line breaks are. Every time you read a line, write it to your output and then write a "<br>" after.
 
Deepa Balasubramanayam
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dirk for your reply. I came to know about Line_Separator. But following is my situation

1)User enter the description in multiple lines(after typing each sentence user strikes enter key for new line).
2)We are using mysql database to store the information.
3)But while displaying the description, instead of seperate statements all the lines are displayed as a paragraph.

For example, above I have entered 3 different statements in the text area. My reply is displayed the same way I entered. But in my case the 3 statements are displayed as a paragraph. New line character is not regonized.
I have to recognize new line character at the end of each statement and replace with <BR> .
Thanks
Deepa
 
Deepa Balasubramanayam
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Jim and Thanks to BufferedReader. My problem is solved.
Thanks
Deepa
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic