0
votes

I have csv file organize as {Id,OwnerUserId,CreationDate,ClosedDate,Score,Title,Body}

I'm trying to split the data using special character. Here example if my data :

 1040,254,2008-08-04T05:45:22Z,NA,42,How do I delete a file which is locked by another process in C#?,"<p>I'm looking for a way to delete a file which is locked by another process using C#. I suspect the method must be able to find which process is locking the file (perhaps by tracking the handles, although I'm not sure how to do this in C#) then close that process before being able to complete the file delete using <code>File.Delete()</code>.</p>
"
1070,236,2008-08-04T07:34:44Z,NA,17,Process size on UNIX,"<p>What is the correct way to get the process size on <code>Solaris, HP-UX</code> and <code>AIX</code>? Should we use <code>top</code> or <code>ps -o vsz</code> or something else?</p>

It seems the data separated by comma but some times the title or body contain comma as well, and seems it has" between the recored. So how can I achieve the following result :

Array 1 { 1040,254,2008-08-04T05:45:22Z,NA,42, title data, body data }
Array 2 { 1070,236,2008-08-04T07:34:44Z,NA,17, title data, body data }

I have tried

String[] tokens = line.split(",(?![^<>]*</>)") 

but didn't work

1
Why do you try to re-invent the wheel? There are many CSV frameworks out there who can handle valid CSV data already. Just use one of them. - Tom
If the csv file is well formed (complies with the CSV specification), you should probably use a CSV parser instead of trying to parse it manually. - assylias

1 Answers

0
votes

You should use some CSV parsing library.

Problem you encounter not the last one. You know that CSV record not always consists of only one string or there is special escape sequences for " symbol?