This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to to recognize new line character?. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to to recognize new line character?." Watch "How to to recognize new line character?." New topic
Author

How to to recognize new line character?.

Deepa Balasubramanayam
Ranch Hand

Joined: Mar 29, 2001
Posts: 39
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

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
Deepa Balasubramanayam
Ranch Hand

Joined: Mar 29, 2001
Posts: 39
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

Joined: Mar 29, 2001
Posts: 39
Thanks to Jim and Thanks to BufferedReader. My problem is solved.
Thanks
Deepa
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to to recognize new line character?.
 
Similar Threads
adding a newline character to a file using fileoutputstream
Java IO Problem
StringBuffer containing '\n'
Replacing character in StringBuffer
Removing linefeed from String.