I found some code that works perfectly with editing a certain section of an ini file, but it only picks up the first instance of the line that I want to edit. I know I can probably just manually input all the indexes in the code from where I want to start the editing, but knowing how things can change over time there might be changes to the ini file and then the indexes will change as well. Can someone shed some light to this issue?
const string FileName = "File.ini";
string file= File.ReadAllText(FileName);
const string Pattern = @"pattern = (?<Number>)";
Match match = Regex.Match(config, Pattern, RegexOptions.IgnoreCase);
if (match.Success)
{
int index = match.Groups["Number"].Index;
string newText= **********;
file = file.Remove(index, 21);
file = file.Insert(index, newText);
File.WriteAllText(FileName, file);
}