Csvhelper: Changing Delimiter Documentation

Created on 19 Jan 2021  路  11Comments  路  Source: JoshClose/CsvHelper

I'm unable to find an example of how to change the delimiter when reading a file.
The following code no longer works since 20.0.0 since the Delimiter parameter is read-only:

csvReader.Configuration.Delimiter = "|";

If you look around the internet (Stack Overflow, etc.) this is always the way that it seems to be done. I can't seem to find an example or pattern on how to now accomplish this.

documentation

All 11 comments

Configuration is read only now. You can pass an instance into the constructor of the reader. The documentation examples are updated. https://joshclose.github.io/CsvHelper/getting-started

The documentation doesn't really say, for example the following wont compile.

Dim config = New CsvConfiguration(CultureInfo.InvariantCulture) With {.Delimiter = fieldDelim}

results in the following errors

'Delimiter' has a return type that is not supported or parameter types that are not supported.
Property 'Delimiter' is 'ReadOnly'.

you have to do it like this:

 var config = new CsvConfiguration(CultureInfo.InvariantCulture)
  {
      Delimiter = "|",
  };

  _bodyWriter = new CsvWriter(swBody,config);

and yea, i agree. update the documentation before stuff breaks =)

@madhon I'm looking into how C#'s record and init works in VB.NET. Since everything compiles down, I figured it would just work. It would be strange if it didn't.

@madhon I created a constructor that takes in every parameter but they're all optional named (except culture). Can you give this a try and see if this fixes things for you?

https://www.nuget.org/packages/CsvHelper/21.0.5-beta0001

@madhon I created a constructor that takes in every parameter but they're all optional named (except culture). Can you give this a try and see if this fixes things for you?

https://www.nuget.org/packages/CsvHelper/21.0.5-beta0001

That works ok for me

@madhon The fix is in 21.0.5 on NuGet. https://www.nuget.org/packages/CsvHelper/21.0.5

@corykroll @EricZimmerman Are the updated docs sufficient?

seems good to me. i think the confusion was having to init everything via the constructor, vs setting properties after.

Great. It was made immutable to solve mutli treading issues.

@JoshClose That worked for me! Thank you for the updated info, I really appreciate it. Sorry for the delay in response, got sidetracked there for a bit.

Was this page helpful?
0 / 5 - 0 ratings