Solved

Open ASCII text file, read into ArrayList

Posted on 2006-11-02
3
1,418 Views
Last Modified: 2012-06-27
I need code that will open an ASCII text file and read each line into an ArrayList, please.
0
Comment
Question by:knowlton
3 Comments
 
LVL 10

Accepted Solution

by:
Kinger247 earned 300 total points
ID: 17860445
knowlton try:

        Dim sr As New System.IO.StreamReader("C:\text.txt")
        Dim Line As String = sr.ReadLine()
        Dim arr As New ArrayList

        Do While Line IsNot Nothing
            arr.Add(Line)
            Line = sr.ReadLine()
        Loop
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 total points
ID: 17860544
Using a regular String Array:

        Dim sr As New System.IO.StreamReader("c:\someFile.txt")
        Dim lines() As String = Split(sr.ReadToEnd, vbCrLf)
        sr.Close()

A variation in loading an ArrayList:

        Dim sr As New System.IO.StreamReader("c:\someFile.txt")
        Dim lines As New ArrayList(Split(sr.ReadToEnd, vbCrLf))
        sr.Close()

With VB.Net 2005 you can make it a one-liner:

        Dim lines As New ArrayList(Split(My.Computer.FileSystem.ReadAllText("c:\someFile.txt"), vbCrLf))
0
 
LVL 5

Author Comment

by:knowlton
ID: 17862854
Thank you so much.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now