Are comments allowed in Windows ini files? (...assuming you're using the GetPrivateProfileString api functions to read them...)
[Section] Name=Value ; comment ; full line comment
And, is there a proper spec of the .INI file format anywhere?
Thanks for the replies - However maybe I wasn't clear enough. It's only the format as read by Windows API Calls that I'm interested in. I know other implementations allow comments, but it's specifically the MS Windows spec and implementation that I need to know about.
Comments in the INI must start with a semicolon (";") or a hash character ("#"), and run to the end of the line. A comment can be a line of its own, or it may follow a key/value pair (the "#" character and trailing comments are extensions of minIni).
How to Open and Edit INI Files. It's not a common practice for people to open or edit INI files, but they can be opened and changed with any text editor. Just double-clicking it will automatically open it in the Notepad application in Windows.
Case sensitivitySection and property names are case insensitive.
ini file is a hidden file used to store information about the arrangement of a Windows folder. Essentially, if the layout or settings for a folder are changed, a desktop. ini file is automatically generated to save those changes.
Windows INI API support for:
;
The authoritative source is the Windows API function that reads values out of INI files
GetPrivateProfileString
Retrieves a string from the specified section in an initialization file.
The reason "full line comments" work is because the requested value does not exist. For example, when parsing the following ini
file contents:
[Application] UseLiveData=1 ;coke=zero pepsi=diet ;gag #stackoverflow=splotchy
Reading the values:
UseLiveData
: 1
coke
: not present ;coke
: not present pepsi
: diet ;gag
stackoverflow
: not present #stackoverflow
: splotchy
Update: I used to think that the number sign (#) was a pseudo line-comment character. The reason using leading # works to hide stackoverflow
is because the name stackoverflow
no longer exists. And it turns out that semi-colon (;
) is a line-comment.
But there is no support for trailing comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With