Home All Groups Group Topic Archive Search About

String Tokenizing - Help!

Author
14 Apr 2006 5:46 AM
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

Author
14 Apr 2006 7:48 AM
Peter Macej
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)})


--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Author
14 Apr 2006 2:52 PM
Claes Bergefall
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

Show quoteHide quote
"Ark" <ah 09763@yahoo-com> wrote in message
news:OYj6r53XGHA.4060@TK2MSFTNGP02.phx.gbl...
> 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
>