Text Area new line
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Text Area new line

  1. #1
    Join Date
    Nov 2011
    Posts
    189

    Text Area new line

    I'm embarassed since this is my 2nd post today...
    Anyways.. I have this text area that holds some lines delimitated by new lines(lines created by pressing enter)

    The problem is that when i transfer the text fo a .txt file all the new lines get lost. This results in a pretty big mess...
    Any simple abordation for solving this?


    BTW: my approach takes the text string as a whole, it doesen't break it down into lines
    Thanks:P

  2. #2
    Join Date
    Jan 2009
    Posts
    596

    Re: Text Area new line

    I presume you are using a jTextArea? These use the '\n' character for new lines, but this may or may not be the correct line separator for text files on whatever OS you are using. You can change new lines to use the line.separator system property, which will give the correct value for your system.

    Just do this before writing your string to file:
    Code:
    theString.replaceAll("\n", System.getProperty("line.separator"));

  3. #3
    Join Date
    Nov 2011
    Posts
    189

    Re: Text Area new line

    do i need to mention that you just saved my day?
    thanks a lot

  4. #4
    Join Date
    Jan 2009
    Posts
    596

    Re: Text Area new line

    Quote Originally Posted by cens View Post
    do i need to mention that you just saved my day?
    thanks a lot
    Any time It's just one of those silly, annoying things to remember - of which there are far too many

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center