First, let me start by thanking you for participating in this site, I have already received so much useful information from it. including some basic analysis of text files in arrays, but now I want to take another step.
I have a text file that looks something like this:
Start Section 1 - foods
apple
bannana
pear
pineapple
orange
end section 1
Start section 2 - animals
dog
cat
horse
cow
end section 2
what I want to do is use one file read by copying the data from section 1 to an array called "products" and section 2 to and an array called "animals"
now I can get it to work, using a new loop for each section, closing and reopening the file each time, looping until I find the section I want and creating an array.
, .
List<string> typel = new List<string>();
using (StreamReader reader = new StreamReader("types.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
typel.Add(line);
}
}
Console.WriteLine(typel[1]);
string[] type = typel.ToArray();
Console.WriteLine(type.Length);
- , , .
, .
,
while ((line = reader.ReadLine()) != Start Section 1 - foods)
{
}
while ((line = reader.ReadLine()) != end Section 1)
{
foods.Add(line);
}
...
....
" 1 - " . , , ?
. .