Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing CSV files with multiple formats in C# using regex
    primarykey
    data
    text
    <p>I have been trying to pass a csv file with three fields. The first two fields are simple and are easily extracted, the problem is with third field which is a string in nature hence can contain special characters including the ',' it self which is used to delimit the fields. I tried containing the string field between two ' " '(double quotes). But my requirement is that for simple string(without special characters) can exist without double quotes. I need to handle the next line in the string also. Below is a sample of a csv file.</p> <blockquote> <p>123,true,This is a memo</p> <p>234,false,"This is also a memo"</p> <p>345,true,</p> <p>456,true,Above me is a blank memo</p> <p>567,false,"This has a ,</p> <p>in it"</p> <p>678,true,This has a , in it &lt;--- This record should be rejected</p> <p>789,false,""</p> <p>890,true,Above me is also a valid blank memo</p> </blockquote> <p>I also found a good tool for testing the regex format string at <a href="http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx" rel="nofollow">http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx</a></p> <p>Till now I have used the following format string ^(""(?:[^""]|"""")<em>""|[^,]</em>),(""(?:[^""]|"""")<em>""|[^,]</em>)$</p> <p>The problem with this format string is that it does not handle multiple lines and does not reject a string with a starting double quote but missing ending double quote.</p> <p>Thanks in advance.</p> <hr> <p>Thanks for the help guys but I needed to parse custom data in CSV and had to create my own custom parser. I am parsing each and every field separately and using regex string in small chunks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload