Results 1 to 8 of 8

Thread: Save to file on new line?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Save to file on new line?

    How can I save text from a textbox onto a new line in a .txt file?
    this is a one-line textbox and I don't want to have any line skips like this

    line 1
    line 2
    line 3

    line 4

    Can anyone please explain how to do this?

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Save to file on new line?

    I'm a bit confused because you say its a "one-line text box" but what you've posted shows multiple lines. Is the problem the empty line between line 3 and line 4 or the fact that each "line" appears on a separate line.

  3. #3
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: Save to file on new line?

    Quote Originally Posted by CoBHC View Post
    How can I save text from a textbox onto a new line in a .txt file?
    this is a one-line textbox and I don't want to have any line skips like this

    line 1
    line 2
    line 3

    line 4
    what s your code to do that ? i think there are many way to do it . please extract your fragment code.
    --***----------***-----

    If i help you please rate me.

    Working with Excel * Working with String * Working with Database * Working with array *

    K51 ĐH BÁCH KHOA HÀ NỘI - Khoa CNTT pro.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Re: Save to file on new line?

    Quote Originally Posted by keystone_paul View Post
    I'm a bit confused because you say its a "one-line text box" but what you've posted shows multiple lines. Is the problem the empty line between line 3 and line 4 or the fact that each "line" appears on a separate line.
    Quote Originally Posted by manhit45 View Post
    what s your code to do that ? i think there are many way to do it . please extract your fragment code.
    Sorry for me being confusing, what I mean is the textbox is not set to multi-line and I want to add the text from the textbox to a .txt file one line at a time so if I put "World" into the textbox and the .txt file already has its first line set to Hello, then it would look like this

    Hello
    World

    It would at first look like this though:

    Hello

    So I hope I was less confusing this time, you see, I'm American, and I can sometimes be misleading.

    And also, What I mean by no blank line like what I said in the OP, I don't want it to randomly skip the first line or any line after that.

  5. #5
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Save to file on new line?

    Ah OK I follow you now.

    How do you know when to write the line of text - are you trapping the enter key or do you have a button or something like that?

    Personally I would declare an array (or List or collection) of strings, and whenever you get the message to add a new line, examine the contents of the textbox and only add it to your array if it is not blank (use trim to make sure that a line of just spaces would be ignored).

    Then I'd write the file all at once when you know you are finished

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Re: Save to file on new line?

    Quote Originally Posted by keystone_paul View Post
    Ah OK I follow you now.

    How do you know when to write the line of text - are you trapping the enter key or do you have a button or something like that?

    Personally I would declare an array (or List or collection) of strings, and whenever you get the message to add a new line, examine the contents of the textbox and only add it to your array if it is not blank (use trim to make sure that a line of just spaces would be ignored).

    Then I'd write the file all at once when you know you are finished
    I have a button. I just want a really basic file saver.

  7. #7
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Save to file on new line?

    I assume that you already know how to write out to a text file as you were saying you just want it to stop putting in spaces?

    If so then I've given you a workable answer above.

    What bit do you not understand?
    Last edited by keystone_paul; May 17th, 2009 at 02:41 PM.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    358

    Re: Save to file on new line?

    Quote Originally Posted by keystone_paul View Post
    I assume that you already know how to write out to a text file as you were saying you just want it to stop putting in spaces?

    If so then I've given you a workable answer above.

    What bit do you not understand?
    Actually I don't know how to write to a text file, that's what I need to know, that spaces part was from when I used a textbox to make a list and at the top it had a space that I didn't want.

Posting Permissions

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



Click Here to Expand Forum to Full Width