PC Review


Reply
Thread Tools Rate Thread

Character separated lines into a collection

 
 
Chris
Guest
Posts: n/a
 
      25th Feb 2004
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
 
Reply With Quote
 
 
 
 
Adrian Forbes [ASP MVP]
Guest
Posts: n/a
 
      25th Feb 2004
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))

"Chris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a macro to copy only 2 lines w/i a cell separated by 4 line breaks poltpar Microsoft Excel Programming 1 15th Apr 2010 12:32 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
Parsing character separated string into individual components =?Utf-8?B?U2hhcm9u?= Microsoft Access Forms 2 25th Sep 2006 09:00 PM
Splitting comma separated lines of an address for mail merge. =?Utf-8?B?Q2h1ZGE=?= Microsoft Excel Misc 1 12th Sep 2006 01:04 PM
Program to resave a collection of .xls files into tab separated .txt files JH Microsoft Excel Programming 2 12th Jun 2006 05:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:53 PM.