public void Parse(string csvData, ref ITable table, CsvReaderOptions csvReaderOptions) { var lines = csvData .Split(csvReaderOptions.NewLine, StringSplitOptions.None) .Select((line, index) => new Row(index, line)); Parse(lines, ref table); }
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); } }
public static ParallelQuery <CsvMappingResult <TEntity> > ReadFromString <TEntity>(this CsvParser <TEntity> csvParser, CsvReaderOptions csvReaderOptions, string csvData) where TEntity : class, new() { var lines = csvData.Split(csvReaderOptions.NewLine, StringSplitOptions.None); return(csvParser.Parse(lines)); }
public static CsvMappingEnumerable <TEntity> ReadFromUrl <TEntity>(this CsvParser <TEntity> csvParser, CsvReaderOptions csvReaderOptions, string url) where TEntity : new() { using WebClient client = new WebClient(); string content = client.DownloadString(url); return(csvParser.ReadFromString(csvReaderOptions, content)); }
public static ParallelQuery<CsvMappingResult<TEntity>> ReadFromString<TEntity>(this CsvParser<TEntity> csvParser, CsvReaderOptions csvReaderOptions, string csvData) { var lines = csvData .Split(csvReaderOptions.NewLine, StringSplitOptions.None) .Select((line, index) => new Row(index, line)); return csvParser.Parse(lines); }