Code Monkey home page Code Monkey logo

tiny-ini-file-class's Introduction

tiny-ini-file-class

A simple tiny class on C# learn your program to read/write ini files..

Example usage #1 (write):

IniFile file = new IniFile("settings.ini");
            
file.Write("hello", "world", "main");
file.Write("2020", "Happy New Year!", "main");

This code creates file (settings.ini), and creates 2 lines under block [main]

[main]
hello=world
2020=Happy New Year!

Example usage #2 (read):

In file settings.ini:

[main]
hello=world
2020=Happy New Year!

Write this code:

IniFile file = new IniFile("settings.ini");

if(file.KeyExists("2020", "main"))
     Console.WriteLine(file.Read("2020", "main"));

This code write in console Happy New Year!

Example usage #3 (delete key):

Also, you can delete all line (key && value), for example:

IniFile file = new IniFile("settings.ini");

if(file.KeyExists("hello", "main"))
     file.DeleteKey("hello", "main");

File settings.ini before operation

[main]
hello=world
2020=Happy New Year!

File settings.ini after operation

[main]
2020=Happy New Year!

Example usage #4 (delete section):

Also, you can delete all values in section (block), for example:

IniFile file = new IniFile("settings.ini");

file.DeleteSection("main");

File settings.ini before operation

; Comment
; Comment2
[main]
hello=world
2020=Happy New Year!

File settings.ini after operation (all block main has been removed)

; Comment
; Comment2

Example usage #5 (file access):

Default access for file - it's a Read And Write, but you can set access manually in code to ReadOnly or WriteOnly. For example, if try write to file without rules, you can't do it and program was generated a new exceprion.

// read & write (default access)
IniFile fileFullAccess = new IniFile("settings.ini", FileAccess.ReadWrite);

// only read access
IniFile fileReadOnlyAccess = new IniFile("settings.ini", FileAccess.Read);

// only write access
IniFile fileWriteOnlyAccess = new IniFile("settings.ini", FileAccess.Write);

//exception on write with Readonly access
fileReadOnlyAccess.Write("hello", "world1", "main");

That`s all! Thanks for reading!

tiny-ini-file-class's People

Contributors

niklyadov avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.