?
Solved

Open ASCII text file, read into ArrayList

Posted on 2006-11-02
3
Medium Priority
?
1,461 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Accepted Solution

by:
Kinger247 earned 1200 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 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 800 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:Tom Knowlton
ID: 17862854
Thank you so much.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

801 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