Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to know if anyone here knows how to implement a code that is able to read an ini.file.

The user need to be able to edit the ini. file
Posted
Comments
Richard MacCutchan 15-Oct-13 9:58am    
See my answer to your other question. Please try and do some basic research rather than posting general questions like this.

Perhaps I should apologise for my rather sarcastic answer - but you did say you needed to know whether anyone here knew how to read a file - which almost everyone does; what you didn't do was ask for guidance on how to do it yourself.

Since many of us are (a) given to sarcasm, and (b) reluctant to do the work that a questioner should have done for themselves it's generally wise to demonstrate that you've made an effort to solve your problem for yourself before you seek help. Also, ask the question for which you want the answer. :)

A more helpful answer to your question, then, is that you should look at the MSDN library at the classes in the System.IO namespace. There, you will find the File class, which has methods that allow you to read a file line by line.

If you need to interpret numbers, true/false values, or named indicator values, you should also look in the System namespace at the int, float, (... other number types), bool and Enum types. They all have a TryParse() method that you can use to safely turn the string representation of the value into a usable value.

If you need to be a little more sophisticated, you can use Regular Expressions (System.Text.RegularExpressions.Regex) - which are very powerful, but equally hard to get your mind around.
 
Share this answer
 
Comments
Nelek 16-Oct-13 6:20am    
my 5
Sorry, I don't participate in surveys.
 
Share this answer
 
Yep, I know.

You open the file. Read the lines one by one, then close the file.

Job done. :)
 
Share this answer
 
Comments
Richard MacCutchan 15-Oct-13 13:27pm    
Sounds like a brilliant solution; I must try it sometime. :)
Have a look at this Stack Overflow question: "Reading/writing an INI file"[^]. And consider, as suggested, using XML files instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900