public static Section[] ProcessFile(string input_file) { string[] filecontents = File.ReadAllLines(input_file); if (filecontents.Length == 0) { return new Section[] {} } ; List <Section> section_list = new List <Section>(); string currentheader = "[beginning of file]"; List <CsvableString> current_stringlist = new List <CsvableString>(); bool on_csvable_section = (new CsvableString(filecontents[0]).IsValid); for (int i = 0; i < filecontents.Length; i++) { CsvableString currentline = new CsvableString(filecontents[i]); bool currentvalid = currentline.IsValid; if (on_csvable_section && !currentvalid) { section_list.Add(new Section((String)currentheader.Clone(), current_stringlist.ToArray())); current_stringlist = new List <CsvableString>(); on_csvable_section = false; } if (!currentvalid) { currentheader = currentline.ToString(); } else { current_stringlist.Add(currentline); } if (!on_csvable_section && currentvalid) { on_csvable_section = true; } } if (current_stringlist.Count > 0) { section_list.Add(new Section(currentheader, current_stringlist.ToArray())); } return(section_list.ToArray()); } }
public static void tests() { CsvableString l = new CsvableString("3.2 er 4.3 1.2 3.6, 4"); l.Summarize(); }