I have an .EDF (text) file. The file’s contents are as follows:
ConfigFile.Sample, Software v0.32, CP Version 0.32
[123_Float][2]
[127_Number][0]
[039_Code][70]
I wnat to read these items and parse them like this:
123_Float - 2
127_Number - 0
039_Code - 70
How can I do this using C#?
Well, you might start with the
File.ReadAllLines()method. Then, iterate through the lines in that file, checking to see if they match a pattern. If they do, extract the necessary text and do whatever you want with it.Here’s an example that assumes you want lines in the format
[(field 1)][(field 2)]:This outputs them to the console window, but you could obviously do whatever you want with
value1andvalue2(write them to another file, store them in a data structure, etc).Also, please note that regular expressions are not my strong point — there’s probably a much more elegant way to check if a line matches your pattern 🙂
If you want more info, check out MSDN’s article on reading data from a text file as a starting point.