dcsimg
Results 1 to 7 of 7

Thread: [RESOLVED] Remove Blank lines from Textbox1

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2015
    Posts
    6

    Resolved [RESOLVED] Remove Blank lines from Textbox1

    Example:


    aaa




    bbb


    bbb




    aaa

    How I want it to be:

    aaa
    bbb
    bbb
    aaa

    Now the problem is I tried almost everything and still it doesn't worked.
    There is someone that can help me with that before I give up on this one?

    Have a Great Day Everyone!

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,117

    Re: Remove Blank lines from Textbox1

    You can get the lines in a TextBox from its Lines property and you can set it using an array as well. You can remove the empty Strings from the array any way you like but the most succinct way is using LINQ:
    Code:
    TextBox1.Lines = TextBox1.Lines.Where(Function(line) line <> String.Empty).ToArray()

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2015
    Posts
    6

    Re: Remove Blank lines from Textbox1

    Quote Originally Posted by jmcilhinney View Post
    You can get the lines in a TextBox from its Lines property and you can set it using an array as well. You can remove the empty Strings from the array any way you like but the most succinct way is using LINQ:
    Code:
    TextBox1.Lines = TextBox1.Lines.Where(Function(line) line <> String.Empty).ToArray()
    Omg bro u are legend!
    Now last 1 thing..
    After I did the code it was working fine as hell, now the problem is like arround 20 blank lines are removed but! there is now 3 lines with 3 spaces. Means:
    I have 3 lines with 1 Space string wrote in it. imagine that [space] is space.
    Example:
    gggg
    [space]
    ggg
    [space]

    the thing is what i need now is a code that remove a lines with just 1 space wrote in it, can u help me with that bro?
    THANKS ALOT BRO APPRECIATE IT~!

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,402

    Re: Remove Blank lines from Textbox1

    If I understand you correctly then using the string "Trim" method should solve your problem.
    Code:
    line.Trim <> String.Empty

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,117

    Re: Remove Blank lines from Textbox1

    This will handle blank lines and those that just contain spaces:
    Code:
    TextBox1.Lines = TextBox1.Lines.Where(Function(line) line.Trim() <> String.Empty).ToArray()

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2015
    Posts
    6

    Re: Remove Blank lines from Textbox1

    Quote Originally Posted by jmcilhinney View Post
    This will handle blank lines and those that just contain spaces:
    Code:
    TextBox1.Lines = TextBox1.Lines.Where(Function(line) line.Trim() <> String.Empty).ToArray()
    LOVE U!
    I amdone u can close thanks!

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,353

    Re: Remove Blank lines from Textbox1

    On this site the one who "closes" the thread is the person who started it, because they are the one who knows when it is solved.

    You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width