Solved

Open ASCII text file, read into ArrayList

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

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:Tom Knowlton
ID: 17862854
Thank you so much.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net convert long time to mm:ss 23 32
VB.net Code to make a TaskPane float in Excel Add-in 2 36
Set arraylist as datatable 2 28
Best book for Internet security 4 52
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

739 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