3 Replies - 2158 Views - Last Post: 26 March 2009 - 01:15 PM Rate Topic: -----

#1 juunas   User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 87
  • Joined: 25-March 09

Reading lines from a text file to an array

Posted 26 March 2009 - 08:32 AM

Okay, what I'm trying to do is to read the lines from a text file, and transfer them to an array.

Is there an easy way to do this?

So basically, what I'm trying to do:

Contents of text file:

First line
Second line
Third line

And I want it to go to an array so the array will look like this

Array(0)="First line"
Array(1)="Second line"
Array(2)="Third line"

Is This A Good Question/Topic? 0
  • +

Replies To: Reading lines from a text file to an array

#2 LemonMan   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 170
  • Joined: 22-August 05

Re: Reading lines from a text file to an array

Posted 26 March 2009 - 08:47 AM

View Postjuunas, on 26 Mar, 2009 - 08:32 AM, said:

Is there an easy way to do this?


Yes. First Import System.Io at the top of your project like this:

Imports System.IO



And then do this:

Dim myArray As String()
myArray = File.ReadAllLines("C:\myfile.txt").ToArray()


Was This Post Helpful? 1
  • +
  • -

#3 juunas   User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 87
  • Joined: 25-March 09

Re: Reading lines from a text file to an array

Posted 26 March 2009 - 08:55 AM

Thank you!
Was This Post Helpful? 0
  • +
  • -

#4 LemonMan   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 170
  • Joined: 22-August 05

Re: Reading lines from a text file to an array

Posted 26 March 2009 - 01:15 PM

No problem! :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1