View Single Post
  #2 (permalink)  
Old April 1st, 2015, 04:00 AM
DeborahStoddard DeborahStoddard is offline
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2015
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default RE: Reading an INI file in C#

I would recommend you to check out this C# library for advance processing of INI files.
It can enable you to bind your data in simple manner, you would need to define a placeholders like this: @{placeholder}

So your INI file's content would be this:

[section]
userName=Mr A
Email=https://www@{number}.@{URL}.com
number=8


And you can execute a binding like the following:

Code:
IniFile file = new IniFile();
file.Load("path-to-ini-file.ini");

// This will bind placeholders with internal data.
// In other words 'number' placeholder will get 'number' key's value.
file.ValueBinding.Bind();

// This will bind placeholders with external data.
// In other words 'URL' placeholder will get KeyValuePair's value.
file.ValueBinding.Bind(
    new KeyValuePair<string, string>("URL", "example"));

// The 'email' variable's value is: https://www8.example.com
string email = file.Sections["section"].Keys["Email"].Value;
Reply With Quote