Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:03:43+00:00 2026-06-08T21:03:43+00:00

Currently I’m writing a library to make reading and writing INI files simple, I

  • 0

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

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)
     {
     }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:03:44+00:00Added an answer on June 8, 2026 at 9:03 pm

    Why rewriting what the system already know how to do? Take a look at this project : An INI file handling class using C#. You should also be aware that Xml has taken a great place in the .Net framework. It’s not uncommon to use either the configuration framework or a simple settings object that you serialize/deserialize. I don’t know you requirement, but it can enlight us to describe a bit why you want to use ini files.

    That said, you are writing the old value (wholedata), not the new value (result). This may be be the root cause.

    When you call Regex.Replace (so do string.Replace), it actually generate a new string, and does not change the string passed in parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently i am working in simple android app, I have tried to range of
Currently, I'm working on a project where I have a server - client relationship
Currently I have the following Mapping in my Controller: @RequestMapping( value = /add.html, method
Currently i am working simple PayPal integration in Android, So i set the Manifest.xml
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently I am using HTML files for parts of my user interface. I display
Currently I have 2 ways of displaying images in a cell, which way will
Currently working with converting SQLException error messages into messages that are more useful for
Currently I have this code: <?php echo '<meta name=robots content=noindex>'; $arr = json_decode(file_get_contents(http://media1.clubpenguin.com/play/en/web_service/game_configs/ paper_items.json),true);
Currently i have a node.js and socket.io application in development on my local machine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.