Question : Removing Lines from richtextbox

I am using the following code, to import a few text files into a richtextbox, then it remove the lines that are the header lines of each file except for the first line.  But when it finishes I end up with a couple of spaces between the lines like so.  I have attached to code snippet.  How can I remove the blanks or for that matter get never create them when removing header lines.  Thanks

997,1885,1571,DDA,12/02/2008 16:50,12/02/2008 16:53,9845264556,5381-9631,Theresea LaBounty,917,,8,69.09,,070518898      019,,103104900,,,,,,d103104900d0070518898      019c                  
997,1885,1572,DDA,12/02/2008 17:19,12/02/2008 17:21,9845264556,5381-9631,Theresea LaBounty,918,,1,300,,070848717      019,,103104900,,,,,,d103104900d0070848717      019c                  
997,1885,1572,DDA,12/02/2008 17:19,12/02/2008 17:21,9845264556,5381-9631,Theresea LaBounty,918,,2,300,,070848716      019,,103104900,,,,,,d103104900d0070848716      019c                  


997,1927,1454,DDA,12/01/2008 8:07,12/01/2008 8:16,9848974748,5381-9631,sheila gayheart,1352,,1,272.5,195,117720896,,41000124,,,,,,d041000124d   117720896c    0!95            
997,1927,1454,DDA,12/01/2008 8:07,12/01/2008 8:16,9848974748,5381-9631,sheila gayheart,1352,,2,388,686,4829326,,44101305,,,,,,d044101305d       4829326c  0686            
997,1927,1454,DDA,12/01/2008 8:07,12/01/2008 8:16,9848974748,5381-9631,sheila gayheart,1352,,3,470,1945,10230048,,244180689,,,,,,d244180689d   10230048c  1945            
997,1927,1454,DDA,12/01/2008 8:07,12/01/2008 8:16,9848974748,5381-9631,sheila gayheart,1352,,4,605,,3874192,,44101305,,,,,,d044101305d1602   c3874192c                  
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
For i = 0 To chkListBox1.CheckedItems.Count - 1
            sSource = lblFolder.Text
            sName = lblFolder.Text + "\" + chkListBox1.CheckedItems.Item(i).ToString
            rtTextFiles.AppendText(IO.File.ReadAllText(sName) & Environment.NewLine)
            'rtTextFiles.Lines(0).Remove(0, 255)
            rtTextFiles.Lines(0) = rtTextFiles.Lines(0).Remove(0, 262)
 
        Next i
 
        ' Now and try to get rid of lines we dont need
        Dim lines() As String = rtTextFiles.Lines
 
        For l = 1 To lines.Count - 1
            If lines(l).StartsWith("Customer Number") Then
                lines(l) = lines(l).Remove(0, rtTextFiles.Lines(l).Length)
 
 
            Else
            End If
        Next l
        rtTextFiles.Lines = lines
        ' now save the file
        rtTextFiles.SaveFile("c:\achtest.csv", RichTextBoxStreamType.PlainText)

Answer : Removing Lines from richtextbox

Try iterating through it in reverse, removing the lines rather then removing the text in the line.  Something like this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
'Use a List(Of String) so we have the RemoveAt function
Dim lines As New List(Of String)
'Add the rtb lines to the list
lines.AddRange(rtTextFiles.Lines)
 
'Loop through the lines in reverse so we can remove lines
'without index issues
For l = lines.Count - 1 To 0 Step -1
    'Check the line beginning and remove it if necessary
    If lines(l).StartsWith("Customer Number") Then
        lines.RemoveAt(l)
    End If
Next l
'Reset the rtb lines to the List usint ToArray
rtTextFiles.Lines = lines.ToArray
Random Solutions  
 
programming4us programming4us