public List <CsvRecord> ParseCsvRecord(string csvContent) { TinyCsvParser.CsvParserOptions options = new TinyCsvParser.CsvParserOptions(true, ','); TinyCsvParser.CsvReaderOptions readerOptions = new CsvReaderOptions(new[] { Environment.NewLine }); var parser = new TinyCsvParser.CsvParser <CsvRecord>(options, new CsvRecordMapping()); return(parser.ReadFromString(readerOptions, csvContent).Select(x => x.Result).ToList()); }
public void Parse_File() { TinyCsvParser.CsvParserOptions csvParserOptions = new TinyCsvParser.CsvParserOptions(true, ';'); TinyCsvParser.CsvReaderOptions csvReaderOptions = new TinyCsvParser.CsvReaderOptions(new[] { Environment.NewLine }); CsvPersonMapping csvMapper = new CsvPersonMapping(); TinyCsvParser.CsvParser <Person> csvParser = new TinyCsvParser.CsvParser <Person>(csvParserOptions, csvMapper); var stringBuilder = new System.Text.StringBuilder() .AppendLine("FirstName;LastName;BirthDate") .AppendLine("Philipp;Wagner;1986/05/12") .AppendLine("Max;Mustermann;2014/01/01"); var result = csvParser .ReadFromString(csvReaderOptions, stringBuilder.ToString()) .ToList(); }
public int TinyCsvParser() { var totalLength = 0; if (Columns == 10) { var csvParserOptions = new TinyCsvParser.CsvParserOptions(false, ',', 4, true); var csvReaderOptions = new TinyCsvParser.CsvReaderOptions(NewLine); var csvMapper = new TinyCsvRecordMapping10(); var csvParser = new TinyCsvParser.CsvParser <Record10>(csvParserOptions, csvMapper); var results = csvParser.ReadFromString(csvReaderOptions, StringFile); foreach (var result in results) { var record = result.Result; totalLength += record.column1.Length; totalLength += record.column2.Length; totalLength += record.column3.Length; totalLength += record.column4.Length; totalLength += record.column5.Length; totalLength += record.column6.Length; totalLength += record.column7.Length; totalLength += record.column8.Length; totalLength += record.column9.Length; totalLength += record.column10.Length; } return(totalLength); } else { var csvParserOptions = new TinyCsvParser.CsvParserOptions(false, ',', 4, true); var csvReaderOptions = new TinyCsvParser.CsvReaderOptions(NewLine); var csvMapper = new TinyCsvRecordMapping50(); var csvParser = new TinyCsvParser.CsvParser <Record50>(csvParserOptions, csvMapper); var results = csvParser.ReadFromString(csvReaderOptions, StringFile); foreach (var result in results) { var record = result.Result; totalLength += record.column1.Length; totalLength += record.column2.Length; totalLength += record.column3.Length; totalLength += record.column4.Length; totalLength += record.column5.Length; totalLength += record.column6.Length; totalLength += record.column7.Length; totalLength += record.column8.Length; totalLength += record.column9.Length; totalLength += record.column10.Length; totalLength += record.column11.Length; totalLength += record.column12.Length; totalLength += record.column13.Length; totalLength += record.column14.Length; totalLength += record.column15.Length; totalLength += record.column16.Length; totalLength += record.column17.Length; totalLength += record.column18.Length; totalLength += record.column19.Length; totalLength += record.column20.Length; totalLength += record.column21.Length; totalLength += record.column22.Length; totalLength += record.column23.Length; totalLength += record.column24.Length; totalLength += record.column25.Length; totalLength += record.column26.Length; totalLength += record.column27.Length; totalLength += record.column28.Length; totalLength += record.column29.Length; totalLength += record.column30.Length; totalLength += record.column31.Length; totalLength += record.column32.Length; totalLength += record.column33.Length; totalLength += record.column34.Length; totalLength += record.column35.Length; totalLength += record.column36.Length; totalLength += record.column37.Length; totalLength += record.column38.Length; totalLength += record.column39.Length; totalLength += record.column40.Length; totalLength += record.column41.Length; totalLength += record.column42.Length; totalLength += record.column43.Length; totalLength += record.column44.Length; totalLength += record.column45.Length; totalLength += record.column46.Length; totalLength += record.column47.Length; totalLength += record.column48.Length; totalLength += record.column49.Length; totalLength += record.column50.Length; } return(totalLength); } }