Hi,
I am creating a VB.NET application that uses multiple lines of a text files as an array member. I came up with this code to create the array:

Dim PSArray as string = Split(my.computer.Filesystem.readalltext ("E:\PS.txt") )

Now that I have created the array, I need to know how I could make each line of the text file an array member.
As an example, here is my "text file"

Fish
Cat
Dog
Mouse

I want to be able to make each animal an array member.

Thanks.

Recommended Answers

All 2 Replies

Try File.ReadAllLines() which returns a string array.

Dim str As String = My.Computer.FileSystem.ReadAllText("E:\PS.txt")
Dim PSArray As String = ""
Dim lines() As String = Split(str, vbCrLf)
For Each line In lines
PSArray = PSArray + line
Next

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.