I have a .ini file
the .ini:
;app ...
[MSGS]
title#0 = first title..
message#0 = first message
title#1 = second title
message#1 = second message
title#2 = third title
message#2 = third message
I’m using the Nini lib for parsing. I need read it to a dictionary.
I tried this:
public Dictionary<string, string> Read()
{
try
{
Dictionary<string, string> result = new Dictionary<string, string>();
IConfigSource src = config;
IConfig values = src.Configs["MSGS"];
string[] keys = values.GetKeys();
for (int count = keys.Length / 2,i = 0, j = 1;
i < count; i++,
j = i + 1)
{
string titleKey = keys[i];
string messageKey = keys[j];
string titleVal = values.Get(titleKey);
string messageVal = values.Get(messageKey);
result.Add(titleVal, messageVal);
}
}
catch (Exception)
{
}
return null;
}
The output is:
first title.. : first message
first message : second title
second title : second message
I want:
first title.. : first message
second title : second message
third title : third message
How I do this?
Thanks in advance. 🙂
1 Answer