reading file into array

J

James

i've a text file in the following format and i would like to read into this
array

text file
======
machine1
machine2

Dim sr As StreamReader = New StreamReader("machines.txt")
dim line as string
Do

line = sr.ReadLine



Loop Until line Is Nothing

sr.Close()

How can i read line by line into this form of array :

dim strcomputer() as string = {"machine1", "machine2"}
 
J

James

dim myArrayList as new Arraylist (does not allow me to define using
the NEW word ..pls advise

etc
etc

myArrayList.Add(line)
 
C

Claes Bergefall

You could also use a StringCollection instead of ArrayList.
Depends on what you want to do with the data once
you're read it

/claes
 
H

Herfried K. Wagner [MVP]

James said:
i've a text file in the following format and i would like to read into
this array

text file
======
machine1
machine2

\\\
Imports System.IO
..
..
..
Dim Reader As New StreamReader("C:\WINDOWS\WIN.INI")
Dim Lines() As String = _
Split(Reader.ReadToEnd(), ControlChars.NewLine)
Reader.Close()
///
 

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