How we can write delimiter like sep=, using CsvHelper library?

Inside the CsvWriter class there is an aptly named WriteExcelSeparator() that should do it.

Depending on how you use the library, you can even:

csv.Configuration.Delimiter = ",";
csv.Configuration.HasExcelSeparator = true;

If you use the WriteRecords, use the second way, while if you use WriteHeader/WriteRecord use the first one.

csv.WriteExcelSeparator();
csv.WriteHeader<Simple>();
csv.WriteRecord( record );

They first changed it to being a parameter of CsvConfiguration and as of 8th of March 2021 it is

var config = new CsvConfiguration(CultureInfo.CurrentCulture) { Delimiter = ";", Encoding = Encoding.UTF8 };
using var csv = new CsvReader(reader, config);

Likely they will change it again in the future ;)

Tags:

C#

Csvhelper