reading file into array

  • Thread starter Thread starter James
  • Start date Start date
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"}
 
dim myArrayList as new Arraylist (does not allow me to define using
the NEW word ..pls advise

etc
etc

myArrayList.Add(line)
 
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
 
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()
///
 
Back
Top