I have tried a regular expression to split a string with comma and space. Expression matches all the cases except only one. The code I have tried is:
List<string> strNewSplit = new List<string>();
Regex csvSplit = new Regex("(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)", RegexOptions.Compiled);
foreach (Match match in csvSplit.Matches(input))
{
strNewSplit.Add(match.Value.TrimStart(','));
}
return strNewSplit;
CASE1: "MYSQL,ORACLE","C#,ASP.NET"
EXpectedOutput:
"MYSQL,ORACLE"
"C#,ASP.NET"
RESULT : PASS
CASE2: "MYSQL,ORACLE", "C#,ASP.NET"
ExpectedOutput:
"MYSQL,ORACLE"
"C#,ASP.NET"
Actual OutPut:
"MYSQL,ORACLE"
"C#
ASP.NET"
RESULT: FAIL.
If I provide a space after a comma in between two DoubleQuotes then I didn't get appropriate output. Am I missing anything? Please provide a better solution.