Yes, there are no built-in classes for this that I know of.
But this should not be a problem, if so? It looks simple enough to parse by simply storing the result of Stream.ReadToEnd() in a line, breaking based on new lines, and then breaking each entry into a = character. What remains for you is a bunch of key pairs that you can easily insert into your dictionary.
Here is an example that might work for you:
public static Dictionary<string, string> GetProperties(string path) { string fileData = ""; using (StreamReader sr = new StreamReader(path)) { fileData = sr.ReadToEnd().Replace("\r", ""); } Dictionary<string, string> Properties = new Dictionary<string, string>(); string[] kvp; string[] records = fileData.Split("\n".ToCharArray()); foreach (string record in records) { kvp = record.Split("=".ToCharArray()); Properties.Add(kvp[0], kvp[1]); } return Properties; }
Here is an example of how to use it:
Dictionary<string,string> Properties = GetProperties("data.txt"); Console.WriteLine("Hello: " + Properties["Hello"]); Console.ReadKey();
Spencer Ruport Jan 27 '09 at 10:50 2009-01-27 22:50
source share