Delete Blank line(s) from a textbox?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 6
Reputation: blackknight469 is an unknown quantity at this point 
Solved Threads: 0
blackknight469 blackknight469 is offline Offline
Newbie Poster

Delete Blank line(s) from a textbox?

 
0
  #1
Sep 3rd, 2009
what is the code for searching for and removing a blank line in a multi-line text box? im using VB Express '08 and can not figure it out.

my problem is im loading a sample.text file and using txtFile.AppendText(ControlChars.NewLine & activetext & ",") to add new text from user input and get a blank line that causes problems when converting the text into my array. it looks like this:
info,info
info,info
info,info
info,info
info,info
info,info

info,info
info,info
please HELP! i am out of ideas and everything else is working except this. all i need is that blank line to go away. lol

any ideas or suggestions would be most appreciated.
can post more of my code if needed.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 270
Reputation: GeekByChoiCe is on a distinguished road 
Solved Threads: 55
GeekByChoiCe GeekByChoiCe is offline Offline
Posting Whiz in Training

Re: Delete Blank line(s) from a textbox?

 
1
  #2
Sep 4th, 2009
to remove the blank lines on reading it ou could do:
  1. Dim tmp() As String = My.Computer.FileSystem.ReadAllText("C:\test.txt").Split(vbNewLine)
  2. For Each newStr As String In tmp
  3. If newStr.Length > 2 Then TextBox1.AppendText(newStr & vbNewLine)
  4. Next

if you want to update the textbox you could do:
  1. Dim tmp() As String = TextBox1.Text.Split(CChar(vbNewLine))
  2. TextBox1.Clear()
  3. For Each line As String In tmp
  4. If line.Length > 1 Then
  5. TextBox1.AppendText(line & vbNewLine)
  6. End If
  7. Next

i've posted both possibility coz it wasnt really clear to me what exactlly u wanted (at what time) ... guess need more coffee
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 148
Reputation: samir_ibrahim is on a distinguished road 
Solved Threads: 16
samir_ibrahim's Avatar
samir_ibrahim samir_ibrahim is offline Offline
Junior Poster

Re: Delete Blank line(s) from a textbox?

 
0
  #3
Sep 9th, 2009
You can try this (not tested deeply)

  1. Dim SearchIn = Me.TextBox1.Text
  2. Dim sb As StringBuilder = New StringBuilder(SearchIn)
  3. Me.TextBox1.Text = sb.Replace(vbCrLf + vbCrLf, vbCrLf).ToString
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1143 | Replies: 2
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC