Currently I'm writing a library to make reading and writing INI files simple, I have got the reader working and writing when the key and value doesn't exist but I cannot update the value easily, I have tried various methods to replace the string however none are practical and the program requires the old value

Here is an example I have tried from here: [Regular Expression to replace unknown value in text file - c# and asp.net](https://stackoverflow.com/questions/8155568/regular-expression-to-replace-unknown-value-in-text-file-c-sharp-and-asp-net)

```
Regex rgx = new Regex(@"SQL-SERVER-VERSION="".*?""");
string result = rgx.Replace(input, replacement);

```

But every time I modify that code to replace the value it ends up replacing the key instead thus resulting in an error when the app tries to read the file next time.

Here is the code I am using currently:

```
private string wholedata;
private void UpdateKey(string key, string path, string newval)
{
    try
    {
        using (StreamReader s = new StreamReader(File.Open(path, FileMode.Open)))
        {
            wholedata = s.ReadToEnd();
            Regex rgx = new Regex(key + ".*?");
            string result = rgx.Replace(wholedata, newval);
            MessageBox.Show(result);
        }
        using (StreamWriter s = new StreamWriter(File.Open(path, FileMode.OpenOrCreate)))
        {
            s.Write(wholedata);
        }
     }
     catch (Exception e)
     {
     }
}

```