Splitting a string without using an (eww) textbox

Invisionsoft

Well-known member
Joined
Apr 20, 2007
Messages
64
Location
United Kingdom
Programming Experience
1-3
Hi folks,

I am ashamed to say this but I am using a textbox to split up a string:

VB.NET:
Dim rtb As New TextBox
rtb.Text = System.IO.File.ReadAllText("C:\blah.txt")
For Each XDSLine As String In rtb.Lines
   If XDSLine.StartsWith("%") Then
      FinalXDSLines.Add(XDSLine.Substring(1))
   End If
Next

I have a text file which looks like:

%James
%Bob
%John

I want any lines beginning with % to be shoved into a collection so I can work with it later. I have tried the following:

VB.NET:
For Each XDSLine As String In System.IO.File.ReadAllText("C:\blah.txt").Split(Environment.NewLine)
   If XDSLine.StartsWith("%") Then
      FinalXDSLines.Add(XDSLine.Substring(1))
   End If
Next

But it's an epic fail.

I want to do it properly without a textbox, what's the right way?
 
IO.File.ReadAllLines
 
Back
Top