Cheat Sheet

A Beginners Guide to INI Files

This tutorial will teach you how you can get started to reading and writing INI configuration files.
Captain Salem 2 min read
A Beginners Guide to INI Files

INI files are configuration files that are used by many programs to store settings. They are typically plain text files with a basic structure consisting of sections denoted by square brackets and key-value pairs withn those sections.

Here is an example of an INI file:

Copy code
[section1]
key1 = value1
key2 = value2

[section2]
key3 = value3
key4 = value4

Each section can contain multiple key-value pairs, and the text denotes the section name within the square brackets. An equal sign separates the key and value; the value can be a string, a number, or a boolean value (e.g. true or false).

INI files are often used to store program settings, such as the file's location or window size. They can also store data that needs to be shared between multiple programs or modules.

INI files can be read and written using a variety of programming languages, including C, C++, and Python. Many libraries and utilities are also available for working with INI files in different languages.

Comments

In INI files, comments can be added by starting a line with a semicolon (;) or a hash symbol (#). Anything after the semicolon or hash symbol on that line will be ignored by the program reading the INI file.

Example of comments in INI files.

Copy code
; This is a comment
# This is also a comment

[section1]
key1 = value1 ; This is a comment on the same line as a key-value pair
key2 = value2

[section2]
# This is a comment on its own line
key3 = value3
key4 = value4

Escape Characters

In INI files, certain characters have special meanings and need to be escaped if they are to be treated as literal characters. For example, the equal sign (=) is used to separate keys from values, and the square brackets ([ and ]) are used to denote sections.

The following are some escape characters supported by INI parsers.

\\	\ (single backslash, escape escape character)
\'	apostrophe
\"	double quotes
\0	null character
\a	ringtone/alert/sound
\b	Backspace, [Bell character] for some applications (https://en.wikipedia.org/wiki/Bell_character)
\t	tab character
\r	carriage return
\n	newline
\;	semicolon
\#	number sign
\=	equal sign
\:	colon
\x????	Unicode character for the hexadecimal code point corresponding to ????

INI Interpreters

Popular INI interpreters for various languages.

We hope you enjoyed this tutorial. Leave us a comment down below and share!!

If you enjoy our content, please consider buying us a coffee to support our work:

Share
Comments
More from GeekBits

Join us at GeekBits

Join our members and get a currated list of awesome articles each month.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to GeekBits.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.