csv - C# CsvHelper not trimming the spaces in the fields -


i'm using csvhelper http://csvhelper.com version 2.16.3. want parse csv file trimming spaces in every cell.

this failing unit test

    [fact]     public void getnextbatch_should_trim_every_cell()     {         var csvservice = new csvservice();         var stream = new memorystream();         var streamwriter = new streamwriter(stream);         streamwriter.writeline("  123  , hello ");         streamwriter.flush();         stream.position = 0;          var csvparser = new csvparser(new streamreader(stream, true), new csvconfiguration         {             isheadercasesensitive = false,             skipemptyrecords = true,             trimfields = true,             trimheaders = true         });          var res = csvservice.getnextbatch(csvparser, 10);         assert.equal("123", res.first()[0]);         assert.equal("hello", res.first()[1]);     }      public ienumerable<string[]> getnextbatch(csvparser csvparser, int batchsize)     {         var list = new list<string[]>();         while (list.count < batchsize)         {             var rows = csvparser.read();             if (rows == null)                 break;             list.add(rows);         }         return list;     } 

when run test result

assert.equal() failure ↓ (pos 0) expected: 123 actual: 123
↑ (pos 0)

what i'm doing wrong? thanks

i using library in wrong way, instead of csvparser should use csvreader suggested in documentation.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -