All Projects → Enichan → Ini

Enichan / Ini

Licence: mit
Ini file reader/writer for C# / .NET written in pure .NET in a single source file

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Ini

Bitio
Optimized bit-level Reader and Writer for Go.
Stars: ✭ 145 (+237.21%)
Mutual labels:  reader, writer
maildir
A Go package for reading & writing messages in maildir format
Stars: ✭ 13 (-69.77%)
Mutual labels:  writer, reader
Qtcsv
Library for reading and writing csv-files in Qt.
Stars: ✭ 156 (+262.79%)
Mutual labels:  reader, writer
Cistern
Ruby API client framework
Stars: ✭ 81 (+88.37%)
Mutual labels:  reader, writer
Asmresolver
A library for editing PE files with full .NET metadata support
Stars: ✭ 267 (+520.93%)
Mutual labels:  reader, writer
Parquet4s
Read and write Parquet in Scala. Use Scala classes as schema. No need to start a cluster.
Stars: ✭ 125 (+190.7%)
Mutual labels:  reader, writer
mp4-rust
🎥 MP4 reader and writer library in Rust! 🦀
Stars: ✭ 149 (+246.51%)
Mutual labels:  writer, reader
Iostreams
IOStreams is an incredibly powerful streaming library that makes changes to file formats, compression, encryption, or storage mechanism transparent to the application.
Stars: ✭ 84 (+95.35%)
Mutual labels:  reader, writer
simple-ini-reader
Fast, Simple, Public Domain INI Reader written in C
Stars: ✭ 17 (-60.47%)
Mutual labels:  reader, ini
iobit
Package iobit provides primitives for reading & writing bits
Stars: ✭ 16 (-62.79%)
Mutual labels:  writer, reader
Xopen
open files for buffered reading and writing in #golang
Stars: ✭ 55 (+27.91%)
Mutual labels:  reader, writer
Choetl
ETL Framework for .NET / c# (Parser / Writer for CSV, Flat, Xml, JSON, Key-Value, Parquet, Yaml, Avro formatted files)
Stars: ✭ 372 (+765.12%)
Mutual labels:  reader, writer
Acr122u Reader Writer
A simple tool to read/write Mifare RFID tags with an ACR122U device
Stars: ✭ 169 (+293.02%)
Mutual labels:  reader, writer
java-class-tools
Read and write java class files in Node.js or in the browser.
Stars: ✭ 27 (-37.21%)
Mutual labels:  writer, reader
Spout
Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
Stars: ✭ 3,861 (+8879.07%)
Mutual labels:  reader, writer
Xml
XML without worries
Stars: ✭ 35 (-18.6%)
Mutual labels:  reader, writer
Oho Reader
【停止维护】哦豁阅读器!API源自追书神器,免费使用!填坑完成!使用react
Stars: ✭ 571 (+1227.91%)
Mutual labels:  reader
Writeinifile
Write-ini-file php library for create, remove, erase, add, and update ini file
Stars: ✭ 12 (-72.09%)
Mutual labels:  ini
Goconfig
Package goconfig is a fully functional and comments-support configuration file (.ini) parser.
Stars: ✭ 568 (+1220.93%)
Mutual labels:  ini
Sciencefair
The futuristic, fabulous and free desktop app for working with scientific literature 🔬 📖
Stars: ✭ 561 (+1204.65%)
Mutual labels:  reader

Ini

Ini file reader and writer for C# written in pure .NET in a single source file.

Supports bools (case insensitive true/false), integers, doubles, and strings. Strings can have whitespace preserved or not, and can have exterior quotes or not. Defaults to case insensitive string comparisons for keys (section names and variable names), but this can be changed by changing the StringComparer field, or by changing IniFile.DefaultStringComparer for all future instances.

Comments are ignored and not saved. Inline comments at the end of values are not supported. Anything before the first section is also ignored.

Empty sections are not saved unless SaveEmptySections is set to true. Whitespace surrounding section names is removed on save and load. It is not removed while working with an IniFile instance, because this could create undesirable behavior.

Attempting to retrieve missing sections or values through indexing will not throw exceptions.

Saving

var ini = new IniFile();

ini["test1"]["boolA"] = true;
ini["test1"]["boolB"] = false;
ini["test1"]["boolC"] = "TRUE";
ini["test1"]["boolD"] = "FALSE";
ini["test1"]["intA"] = 8;
ini["test1"]["intB"] = "not an int";
ini["test1"]["doubleA"] = 0.238471;
ini["test1"]["doubleB"] = "not a double";
ini["test1"]["doubleC"] = "NaN";

ini["test2"]["str"] = "normal string";
ini["test2"]["quotstr"] = "\"quoted string\"";
ini["test2"]["wstr"] = "    whitespace string    ";
ini["test2"]["wquotstr"] = "      \"      quoted whitespace string     \"     ";

ini.Save("test.ini");

Loading

var ini = new IniFile();

ini.Load("test.ini");
Console.WriteLine(ini.GetContents());

Console.WriteLine(ini["test1"]["boolA"].ToBool());
Console.WriteLine(ini["test1"]["boolB"].ToBool());
Console.WriteLine(ini["test1"]["boolC"].ToBool());
Console.WriteLine(ini["test1"]["boolD"].ToBool());
Console.WriteLine(ini["test1"]["intA"].ToInt(-1));
Console.WriteLine(ini["test1"]["intB"].ToInt(-1));
Console.WriteLine(ini["test1"]["doubleA"].ToDouble(-1));
Console.WriteLine(ini["test1"]["doubleB"].ToDouble(-1));
Console.WriteLine(ini["test1"]["doubleC"].ToDouble(-1));

Console.WriteLine(ini["test2"]["str"].GetString());
Console.WriteLine(ini["test2"]["quotstr"].GetString(true, false));
Console.WriteLine(ini["test2"]["quotstr"].GetString(false, false));
Console.WriteLine(ini["test2"]["wstr"].GetString(true));
Console.WriteLine(ini["test2"]["wstr"].GetString(false));
Console.WriteLine(ini["test2"]["wquotstr"].GetString(true, false));
Console.WriteLine(ini["test2"]["wquotstr"].GetString(false, false));
Console.WriteLine(ini["test2"]["wquotstr"].GetString(true, true));
Console.WriteLine(ini["test2"]["wquotstr"].GetString(false, true));

If you want to know whether the conversion succeeded instead of supplying a default value for invalid conversions, use TryConvertBool, TryConvertInt, and TryConvertDouble functions.

You can also enumerate sections and values within sections:

foreach (var section in ini) {
    Console.WriteLine(string.Format("Section {0} found, with {1} entries", section.Key, section.Value.Count));

    foreach (var item in section.Value) {
        Console.WriteLine(string.Format("Item {0} found, value is {1}", item.Key, item.Value));
    }
}

Ordering

By default sections will not preserve the order of items. In order to preserve the order of items within a section, set the IniSection's Ordered property to true, or specify ordered=true when calling IniFile.Add. Ini files can also be loaded with their order preserved by specifying ordered=true when calling IniFile.Load.

Ordered IniSection instances have the following additional methods available: IndexOf, LastIndexOf, Insert, InsertRange, RemoveAt, RemoveRange, Reverse, GetOrderedValues, and can be indexed using integers. Calling these methods on a non-ordered section will result in an InvalidOperationException being thrown.

Take note that the Keys property of an ordered IniSection will be the keys in order, but the Values property does not have the order guaranteed. To get the in-order values of an IniSection use the GetOrderedValues method, or enumerate the section using foreach.

Both ways of iterating over values below are functionally equivalent for an ordered section.

var ini = new IniFile();
ini.Load("somefile.ini", ordered: true);
var section = ini.First().Value;

var index = 0;
foreach (var item in section) {
    Console.WriteLine(string.Format("Item at index {0} is {1}", index, item.Value.GetString()));
    index++;
}

for (var i = 0; i < section.Count; i++) {
    Console.WriteLine(string.Format("Item at index {0} is {1}", i, section[i].GetString()));
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].