Hi,
Our requirement is to parse the input file(.csv format). The each column in the file is delimited with comma. We need to take each column and apply some business validation rule.
If data itself contains comma, then those fields are enclosed with double quotes ("). We can see this double quotes symbols by opening the csv file in notepad or wordpad.
Some times, data itself contains double quotes, in those cases the data is enclosed in double quotes also for each double quotes, one extra double quotes is added. You can see them if we open in notepad or word pad.
Sample example of the csv file when opened in notepad is as shown below
Test.csv
This,test is,with out comma or double quotes
This,"test, contains",comma
This,"test contains ""double quotes"" ","and , comma"
Output required is:
1st Line:
Field1:This
Field2:test is
Field3:with out comma or double quotes
2nd Line:
Field1:This
Field2:test, contains
Field3:comma
3rd Line:
Field1:This
Field2:test contains "double quotes"
Field3:and , comma
If you save the above file contents into a csv file and open in excel, then you will see column values in each line matches my required output.
I tried hard and could not get right way to do this. Please help me in achieving the above.
I have attached test.csv for the reference purpose.
Thanks in advance,
Venkat