Contains sectionPair. Section sections. Add sectionPair. Write strToSave ; tw. WriteLine newMessage ; Console. Follow Post Reply. What about comments in the ini file? If you look through the code - all you have to do is to add another conditional statement as shown here modified sections in bold : Expand Select Wrap Line Numbers. WernerCD 1. My kingdom for this parser in a class. I'm trying to get this wedged into a class file so I can use it in a few places, since I really do like the layout of it, but when I move it and put it into a namespace it just acts all wonky on me.
FYI The whole thing will fail if you have a duplicate key pair. You may want to extend to handle that situation. It's very well documented and uses indexers like a dictionary to contact with the properties. I suggest to give a try! Post Reply. How to stop reading a file? Parsing file to extraction records. Reading a file Andrew Au Andrew Au 3 3 silver badges 11 11 bronze badges. The same is true for public on internal variables, Eric wrote about that one in length I agree with him that public is the better choice fwiw.
As for "Why do you use Logger to encapsulate the Console for output" I do this as I wish to shutdown after any key is pressed, the application cannot run without a valid configuration so it would be pointless to continue running. The reason I also made it only for console is I would only be using it on console.
I have no desire in changing what it runs on, it was made specifically for this console application and not to run on any kind of. Having a parameter string path and using it to load the configuration would be a better way.
LoadConfig I don't like the Console. A better way would be to just use the bool TryGetXxx style. How I would do this: I would add an overloaded public constructor which takes a string fileName parameter. I would validate the fileName parameter and would throw the expected exceptions. ReadLines fileName.
Community Bot 1. Heslacher Heslacher The only advice I didn't take was making 'TryGetValue' a bool, I made it a string as if it was a bool I would have to declare variables for the returned value, my current code just passes the void as it would pass a string.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.
Related 2. Hot Network Questions. Re: Sorted option for sections and keys elias pizarro 8-Nov I figured out dirty fix : VB. Add s Next sList. Compare x. Name, y. WriteLine String. Name oWriter. IniKey In s. Keys kList. Add k Next kList.
Sort Function x As IniSection. IniKey, y As IniSection. IniKey String. IniKey In kList If k. Empty Then Trace. Name, k. Value oWriter.
Value Else Trace. IniKey Next oWriter. Close End Sub modified Nov pm. Convert Class to VB. NET dylan Oct Please, could you convert class IniFile in VB. I tryed with online converters but without success Thanks in advance. Re: Convert Class to VB. NET elias pizarro 8-Nov My vote of 5 kevin.
Many thanks.. Was struggling to work with developing, reading INI files. This tool makes it lot easier Keys are in a different order than the file gary hagerty Mar Hello, I have a VB. Keys ' Do stuff Next Not sure what I am doing wrong. Please advise Thank you.
Re: Keys are in a different order than the file Member Jun I recently experience a similar issue. The answer to this is buried in the comments. Re: handling key values that have equal signs in them Ludvik Jerabek Nov I think I finally got the it right. Honestly it would have been easier to manually parse this rather than using Regex.
Singleline Or RegexOptions. Multi-Line values Derek Jempson Sep Derek Jempson. What's the preferred method for dealing with multi-line values? I can add multi-line values by using line breaks and the line breaks are then reproduced as line breaks in the ini file, but there are problems with editing, or deleting such entries. Is there a more elegant solution?
Excellent project btw.
0コメント