ValueDelimiter without extra space when updated value

Feb 19, 2014 at 9:09 AM
Hi!

Im using KBcsv version 2.01. I have a file where i need to cut the length of a value. The problem is that when I do this and update the datarecord at a certain column KBcsv adds a value delimiter that changes the length of the field.

Example:

Given the following record:
Col1;Col2,Col3
1;TextTextText;SomeText

The following code:
dataRecord["Col2"] = dataRecord["Col2"].Substring(0, 4);

Gives me the following output with ValueDelimiter set to '\0'
Col1;Col2,Col3
1; Text ;Sometext

I would like it to look like (notice there is no empty space at both sides of the Col2 value:
Col1;Col2,Col3
1;Text;Sometext

/Best Regards Anders
Coordinator
Feb 21, 2014 at 1:47 AM
Hi Anders,

Firstly, surely you mean to have a semicolon rather than a comma between Col2 and Col3? Secondly, can you please post a code snippet? I can't repro this with the following code:
static void Main(string[] args)
{
    var csv = @"Col1;Col2;Col3
1;TextTextText;SomeText";

    using (var reader = CsvReader.FromCsvString(csv))
    {
        reader.ValueSeparator = ';';
        reader.ValueDelimiter = '\0';

        reader.ReadHeaderRecord();
        var dataRecord = reader.ReadDataRecord();
        dataRecord["Col2"] = dataRecord["Col2"].Substring(0, 4);

        Console.WriteLine(dataRecord);
    }

    Console.ReadKey();
}
Best,
Kent