I\'m trying to read a text file which contains numbers separated by a comma. When I read using File.Readline()
I get it to a string[]
. I need to conver
Using List
can help you, and use StringSplitOptions.RemoveEmptyEntries
to prevent null exception
in Convert.ToInt64
var lineArray = new List>();
foreach (var lineString in File.ReadAllLines("path"))
{
var line = new List();
string[] values = lineString.Split(new[] { ',', ' ' },
StringSplitOptions.RemoveEmptyEntries);
line.AddRange(values.Select(t => Convert.ToInt64(t)));
lineArray.Add(line);
}
and using it:
// Array of numbers for specific line
var resultArray = lineArray[lineNumber].ToArray();