Character separated lines into a collection

C

Chris

Via a TCP/IP socket, I receive two lines of comma separated text. The
first line is always the titles of all the columns. The subsequent
line is the data for each column. How do I split out the titles and
the data, put them in an array or collection of some kind, pull the
data for one of the titles, modify it, and write it back to the same
spot in the array?

Thanks for help,

Chris
 
A

Adrian Forbes [ASP MVP]

This code makes a two-dimenstional arraylist, or an arraylist of array lists
holding your data

Dim sText As String
Dim aList As New ArrayList

' This is hard-coding the text, you will have got this from the
stream
sText = "A,B" & ControlChars.CrLf & "C,D"

' Create an ArrayList to store each line but splitting the text at
the CrLf
Dim aRows As New ArrayList
aRows.AddRange(sText.Split(ControlChars.CrLf))
' Loop around each row
Dim sRow As String
For Each sRow In aRows
' Add an ArrayList made from splitting each row at the comma
aList.Add(New ArrayList(sRow.Trim.Split(",")))
Next

Debug.WriteLine("First column name is " & CType(aList(0),
ArrayList).Item(0))
Debug.WriteLine("Second column name is " & CType(aList(0),
ArrayList).Item(1))

Debug.WriteLine("First row first column is " & CType(aList(1),
ArrayList).Item(0))
Debug.WriteLine("First row second column is " & CType(aList(1),
ArrayList).Item(1))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top