String Tokenizing - Help!

  • Thread starter Thread starter Ark
  • Start date Start date
A

Ark

Hello,

I have a text file that has each line that is comma seperated, and I need to
get the values into an array. I have worked with Java and have used
StringTokenizer, but have been looking for that kind of thing in Vb.NET.
Will appreciate any advice on what to use, thanks!!

Ark
 
String.Split is not exactly the same but it does the job. To get lines
you can use:

Dim lines() As String
'use VB Split instead of System.Split for 2-char long delimiter
lines = Split(myString, vbCrLf)

To get values on one line:
Dim tokens() As String
tokens = line.Split(","c)

To get values from all lines:
Dim tokens() As String
'String.Split only accepts one char long delimiters, so modify
'2-char vbcrlf to vbcr
myString = myString.Replace(vbCrLf, Chr(13))
tokens = myString.Split(New [Char]() {","c, Chr(13)})
 
Dim sr As New System.IO.StreamReader("TestFile.txt")
Dim line As String = sr.ReadLine()
While line IsNot Nothing
Dim values() As String = line.Split(","c)
line = sr.ReadLine()
End While

/claes
 
Back
Top