我有一个.ini
.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
我正在使用Nini lib 进行解析。我需要把它读到字典里。
我试过这个:
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;
}
输出是:
first title.. : first message
first message : second title
second title : second message
我想:
first title.. : first message
second title : second message
third title : third message
我该怎么做?提前致谢。:)