Hi Dw.
I'm trying to read a text file. This text file has a multiply lines and what I want is that I want to separate each line or should I say I want to split each line (chop it) so that I will be able to assign these fields to variables using the array.
What I first did is to get the lines then for each line I need to break it. The split I'm using the "*" as a separator.
Each line will produce/has 13 fields so I want to get these as a variable. Here is just 1 line example of how each line is:
D1*X584635*test.one*12643820000000000?*D2*65496321476=2416317950000000000*(Y@12345)*Date:*05*April*2016*Time:*17*01*32
So that is just one line. There are quite a number of lines in a file with this format but has different data as to this but the format is the same. Ow also some lines ends with # and also there are some blank lines as well within the file.
This is what I have:
If My.Computer.FileSystem.FileExists("C:\test.txt") Then
Dim test As String = IO.File.ReadAllText("C:\test.txt")
Dim lines() As String = Split(test, vbCrLf)
For Each line As String In lines
' Now I have the collection of lines now
' What I want to achieve is to split each
' Line into array so that I can use some
' Thing like MyArray(0), MyArray(1) etc
' This is what I have but I don't want it
' Like this.
Dim words As String() = line.Split(New Char() {"*"})
Dim data As String
For Each data In words
data.Trim({"#"c, "D1"c, "D2"c})
If data = "" Then
Else
' For now I just use the listbox to display.
ListBox1.Items.Add(data.Trim({"#"c, "D1"c, "D2"c})
End If
Next
Next
This only uses one variable which is data but what I want is to use many variables so I want to maybe add these to an array.