0

Hi, I am trying to write a somewhat basic program to read and write to a .cfg file(text file).

Inside the .cfg file are a bunch of lines like so:

server 127.0.0.1
servername Test
server_no 1
server_group 1

etc, etc.

The first word in the line being the name and second being the value. What I am wanting to do is to read/load all of these values into separate text boxes, be able to edit them, and then save/write them back to the file(append).

What I am needing assistance with is how to read the information and write the information since the name needs to stay the same, and I just need to edit the value.

Basically I would like it to search the document, find the name string, and load whatever the value is into the text box.

Any assistance would be appreciated. Thanks.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by PsychoCoder
0

Hi,
What could you do is use the standar "key=value" style in you configuration file.
Then you should be able to read the whole text, then split the keys & the values, by setting the seperator to be the '='. Then when you want to write back to the file, then you simply delete all the content from your file, and you write them back again, this time with the new values.

Hope i helped,
Alex :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.