I am using ParseCSV function to parse a CSV file in C#.
The last column in a row of CSV file contains: NM 120922C00002500(lots of spaces after this)
In ParseCSV function i am passing an inputstring, as a result of reading the CSV file.
A part of the inputstring is:
"1",000066,"07/30/2012","53193315D4","B ","99AAXXPB0"," "," "," ","CALL NM 09/22/12 00002.500 ","MG",100.00,1.050000,310,32550.00,25530.70,360,37800.00,30477.78,"C",2.50000,09/22/2012,"NM","NM 120922C00002500".
in the CSVParse function, am doing the following:
string csvParsingRegularExpressionOld = Prana.Global.ConfigurationHelper.Instance.GetAppSettingValueByKey("CSVParsingRegularExpression");
string csvParsingRegularExpression = csvParsingRegularExpressionOld.Replace("\\\\", "\\");
In csvParsingRegularExpression value comes out as:
((?<field>[^",\r\n]*)|"(?<field>([^"]|"")*)")(,|(?<rowbreak>\r\n|\n|$))
The I follow up with
Regex re = new Regex(csvParsingRegularExpression);
MatchCollection mc = re.Matches(inputString);
foreach (Match m in mc)
{
field = m.Result("${field}").Replace("\"\"", "\"");
}
But here field contains empty string when it comes to the last value "NM 120922C00002500". What may be the possible solution for this problem?
I dont know if there's a problem with the CSV file or with the regex method "Matches".