© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
11 replies
Estal

❔ Replace multiple Lines

What I had before was
 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);
 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.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

StreamWriter writing some lines multiple times
C#CC# / help
2y ago
❔ Shortcut for selecting multiple lines on windows
C#CC# / help
4y ago
❔ Lines for multiplacation table
C#CC# / help
3y ago
❔ Drawing lines in WPF
C#CC# / help
4y ago