I have properties file as follows:. I want to store it in Dictionary(Key-Value pair).
paragraph1~Para1 Line1
Para1 Line2
Para1 Line3
paragraph2~Para2 Line1
Para2 Line2
paragraph3~Para3 Line1
Para3 Line2
Para3 Line3
I use following code - but it can only parse 1 line. It does not parse multi line. So for dict["paragraph1"], value is "Para1 Line1"
foreach (var row in File.ReadAllLines("c:\\temp\\properties.txt"))
{
if (row == String.Empty)
{
continue;
}
dict.Add(row.Split('~')[0], string.Join("~", row.Split('~').Skip(1).ToArray()));
}
From what I understand from the question this should work:
Produces [paragraph1, Para1 Line1 Para1 Line2 Para1 Line3].
Not entirely sure what you're doing with the string.Join, though. This would produce the same output: