split method

layla

Member
Joined
Apr 26, 2005
Messages
21
Programming Experience
Beginner
does anyone know how to split a tabbed delimited text file and read each column into a different dynamic array? The first two columns consist of strings and the last two columns are doubles.

:)
 
Read a line into a string, then use .split(ChrW(9)) to put it in an array. Then just move the values to your arraylists.
 
Someting like this:
VB.NET:
dim reader as new io.streamreader ("Your file")
dim temparray() as string
dim a,b,c as new arraylist
 
while reader.peek > -1
temparray()=readre.readline.split(chrw(9))
a.add(temparray(0))
b.add(temparray(1))
c.add(temparray(2))
end while
 
also i get the error at the line:
temparray(0) = reader.ReadLine.Split(ChrW(9))

saying :
Value of type '1-dimensional array of String' cannot be converted to 'String'.


help!
 
the last problem was solved. The error now reading is :
object reference not set to an instance of an object

:-(
 
sorry yes about the typo that was reader not readre. object reference not set to an instance of an object = your missing a new. Check you put new io.streamreader and new arraylist.
 
i have: so the new is there

Dim reader As New IO.StreamReader("C:\testing2.txt")
Dim temparray() As Array

Dim a As New ArrayList

While reader.Peek > -1
temparray(0) = reader.ReadLine.Split(ChrW(9)) 'move data into an array

a.Add(temparray(0))

 
example text file: abc def
hij klm


The following code puts the data into an arraylist called a and prints: hij klm
I only want abc and hij to be in array a at position 0 and 1.
I want def and klm to be in array to.
Please someone tell me how to do this and how to split this string and where to put that into the code below??????? it would be much appreciated. im going mad.

Dim i As Integer


Dim reader As New IO.StreamReader("C:\testing2.txt")
Dim temparray(0) As String
Dim a As New ArrayList
While reader.Peek > -1
temparray = reader.ReadLine.Split("ChrW(9)")
End While
RichTextBox1.Text = a.Item(1)
End While
End With
Catch es As Exception
MessageBox.Show(es.Message)
Finally
If Not (sr Is Nothing) Then
sr.Close()
End If
End Try
End Sub

 
Take the 0 here:Dim temparray() AsString
You also need to add the items to the arraylist(s) as I showed you above.

 
Back
Top