Solved

Open ASCII text file, read into ArrayList

Posted on 2006-11-02
3
1,407 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

708 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

16 Experts available now in Live!

Get 1:1 Help Now