Issue with Embedded CRLF

Sep 19, 2013 at 7:15 PM
Kent:

I have some text files that contain TEXT fields and those text fields sometimes contain CRLF inside the field. Which obviously screws up the record break.

Example:

"field 1","Field 2","Field 3 <CRLF>","Field 4" <CRLF>

This example will break the import because it tries to split the string (2) times. Can you tell me how to resolve that using your 1.4 version of the tool.
Coordinator
Sep 20, 2013 at 12:44 PM
Hi,

Firstly, any reason you're not using at least V2.0.2? I could understand not using V3 if you need to run on .NET 4, but not sure why you'd want to use 1.4...

Anyway, I don't think I understand your question. If Field 3 contains CRLF and is delimited, KBCsv should parse it and include the CRLF in the parsed value. Can you elaborate?

Best,
Kent
Sep 20, 2013 at 12:53 PM
It is treating it as though its the end of the record and not just part of the field. I can certainly try 2.0.2 as long as its backwards compatible. I just did not want to take the time right now to resolve a bunch of issues so I picked the latest version that seemed to be 100% backward compatible. I will give that a shot but it is not just parsing that as I think it believes that when it reaches that point it is the end of the record which it is not.
Sep 20, 2013 at 1:10 PM

I just tried it with 2.0.2 and it had the same result. It thinks this is a record break.

Coordinator
Sep 20, 2013 at 1:12 PM
I can't reproduce this, not even in 1.4. Here's my test code:
namespace KBCsvTest
{
    using Kent.Boogaart.KBCsv;
    using System;

    class Program
    {
        static void Main(string[] args)
        {
            var csv = @"""field 1"",""Field 2"",""Field 3 
"",""Field 4""
";

            using (var reader = CsvReader.FromCsvString(csv))
            {
                var record = reader.ReadDataRecordAsStrings();

                Console.WriteLine("Field count: {0}", record.Length);

                foreach (var field in record)
                {
                    Console.WriteLine(field);
                }
            }

            Console.ReadKey();
        }
    }
}
The output is what I expected:
Field count: 4
field 1
Field 2
Field 3

Field 4
Can you please post a repro for your issue?
Sep 20, 2013 at 1:23 PM

Can you send me an email directly and I will send you the code I am using as well as the file that is failing.

I do not want to publically post this info.

[email removed]