I've got an ini file I'm reading in and I'm trying to read the lines between certain strings. In this instance, I'm trying to get the lines 1=One, 2=Two, 3=Three between the section headers [SECTION1],[SECTION2]. The amount of lines between the two sections can be variable and so I'm trying to create a list and then cycle through that while still reading the file. I then need to create and append these to an XDocument which will be saved on disk.
[SECTION1]
1=One
2=Two
3=Three
[SECTION2]
4=Four
5=Five
6=Six
The code I have for it right now is here:
var lines = File.ReadAllLines(file);
List<XElement> iniValues = null;
string correctPath = null;
foreach (var line in lines)
{
if (Regex.IsMatch(line, @"\[(.*?)\]"))
{
Console.WriteLine(line);
switch (line.Substring(1, line.IndexOf("]") - 1))
{
//Switch cases based off of the matching values
But I can't seem to figure out how to cycle through the lines in the middle and get the lines themselves. I can split it after that but I can't seem to figure out how to get the lines in the middle.