parsing - Parse Configuration File C# -


I need some help in parsing a text file that contains several sections, the file is in the following format:

 ; This is a comment that should not be considered for parsing, color in the 24-bit format #define BLUE 16711680 # Defined red 255 [settings] File name File description v1.0 [SECTION] BLUE N033.56.09.699 W118 [25] [25] I have to leave any comments. I should be able to pull hair value from the # defined section. Finally, I need to parse each line under each header section (like  [SETTINGS] ,  [SECTION] , etc. The file is not limited to these headers .  

What I have now here, but it does not work clearly. string line; while ((line = reader.readline ())! = Null {string [] item = line. Sample ('\ t'); (item (string item in item) (if item (wire item in item). Wires ("[SETTINGS]")} {} (Items wired ("[SECTIOn]")) {}}}

This is the type of data structure you want, so you can use the code given below ....

 The result is too much

  Zero main () {// Our configuration file can get rid of any comment in IEnumerable & lt; string & gt; TextLines = text.Split ('\ n'). Where (line => line with wires (";")); // our 'IEnumerable & lt; String & gt; textLines' commons = string.Join (without text without a string to text without a string; \ n ", textLines); // Retrieve which variables are defined // & gt; & Gt; BLUE 16711680 // & gt; & Gt; Red 255 Dictionary & lt; String, string & gt; Define Variables = textLines Where (line = & gt; line strings (@ "#defined")). Select (line => Reggae. Match (line, @ "# define ([^] *) (. *)"). Oxidation (match = & gt; match group [1]. Value, match = & Gt; match group [2]. Value); // creates a dictionary of those classes that are defined // & gt; & Gt; Settings file name // & gt; & Gt; File descriptions // & gt; & Gt; V1.0 // & gt; & Gt; // & gt; & Gt; Section Blue N033.56.0 9.699 W118.25.09.714 // & gt; & Gt; // & gt; & Gt; SECTION2 Red N033.56.13.675 W118.24.30.908 // & gt; & Gt; N033.56.13.675 W118.24.30.908 // & gt; & Gt; N033.56.16.034 W118.24.07.905 Dictionary & lt; String, string & gt; SectionDictionary = Regex.Matches (Text with commissions, @ "\ [[[[w] *) \] \ n ([^ \ [^ \ \] *)".) .stst and lieutenant; Match & gt; (). Autobox (match => match group [1]. Value, match = & gt; match group [2]. Value); UserConfiguration userConfig = new UserConfiguration {Variables = definedVariables, Settings = sectionDictionary ["SETTINGS"], section = sectionDictionary.Where (dictionary => dictionary.key! = "SETTINGS"). Select (=> New = Key = Dictionary (Dictionary Value = Reggae Match. (Value, @ "(\ w *) ([^ \ [] *)")}) .Ougation (Annie = & Gt; AnonKK, Anon = & gt; New Config {name = anon.Value.Groups [1]. Value, value = anon.Value.Groups [2] .Value.RemoveWhiteSpace ()})}}} Public Category UserConfiguration {public dictionary & lt; string, string & gt; variable {get; set;} public string settings {get} set;} get public dictionary & lt; string, config & gt; section ; Set;}} public class configured {public string name {get} set;} public string value {get} set;}} public static class extension {public static string RemoveWhiteSpace (this string text) {var lines = text.Split ( '\ N'); return string .join ("\ n", select lines (str = & gt; str.Trim ()));}} Const string text = @ "; This is a comment that, Must be ignored; #define BLUE in 24-bit format # 16711680 # defined red 255 [setting] file Name File Description v1.0 [SECTION] BLUE N033 56.0 9.699 W118.25.09.714 [SECTION2] Red N033.56.13.675 W118.24.30.908 N033.56.13.675 W118.24.30.908 N033.56.16.034 W 118.24.07.905 ";    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -