C#C
C#3y ago
Estal

❔ Replace multiple Lines

What I had before was
C#
 string SessionName = File.ReadAllText(ConfigFile);
            SessionName = SessionName.Replace("SessionName=\"" + LoadSetting(ConfigFile, "SessionName") + "\"", "SessionName=\"" + serverName.Text + "\"");
            File.WriteAllText(ConfigFile, SessionName);

            string Password = File.ReadAllText(ConfigFile);
            Password = Password.Replace("JoinPassword=\"" + LoadSetting(ConfigFile, "JoinPassword") + "\"", "JoinPassword=\"" + serverPass.Text + "\"");
            File.WriteAllText(ConfigFile, Password);

I now realize that I'm essentially opening the file every iteration. What I'm trying to figure out is how I can go through multiple lines and write them all at once time. If anyone knows it'd be appreciated. Gonna keep trying to figure it out for the time being.
Was this page helpful?