I have a txt file with 2000 names. When I load in a list, the count is 1 and not 2000. Of course, since it is a text file it is only 1. It turns out that the file is organized with \n\r
inside it. Even though I'm giving Split()
, I still can not load a list with 2000 records or items. How do I do this? That is, get a txt file and divide it into a string list with multiple items, using the \n\r
as separator?
I used this code to populate the array that comes from the txt file:
string[] text = new[] { System.IO.File.ReadAllText(path) };
I did it that way. I found it ugly, but I did not find a prettier solution, I had to make two foreach and that makes me kind of annoying.
string[] text = new[] { System.IO.File.ReadAllText(path) };
foreach (var item in text)
{
string[] linha = item.Split('\n');
foreach (var i in linha)
{
lista.Add(i);
}
}