Daniel Linders
Daniel Linders

Reputation: 31

saving an array in a text file

I have an array in VB with numbers. How can I save this in a txt file?

In R, for example, I do it like this: "write.matrix(A,file=name)". So the array with "name" is also stored in VB and I want to do the same thing here.

regards, daniel

Upvotes: 0

Views: 1494

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460018

You could write it to a csv file, f.e. pipe delimited (because numbers can contain commas):

File.WriteAllText(filePath, String.Join("|", numbers))

File.WriteAllText Method

You can load the array later in this way:

Dim split = From str In File.ReadAllText(filePath).Split("|"c)
            Select Double.Parse(str)
Dim numbers As Double() = split.ToArray()

Upvotes: 1

Related Questions