c# - Importing csv file with commas in it Asp.net -
this question has answer here:
- dealing commas in csv file 21 answers
i importing csv file , column in csv file can have commas in it. when import increases columns .
3,stage3,"desc stage,test,test2",55.98,98.76
this row , want columns :
3, stage3, "desc stage,test,test2", 55.98, 98.76
try this
public static string[] splitcsv(string csvlinewithquotedtextwithcommas) { regex regextoseperate = new regex("(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)", regexoptions.compiled); list<string> result = new list<string>(); string curr = null; foreach (match match in regextoseperate.matches(csvlinewithquotedtextwithcommas)) { curr = match.value; if (0 == curr.length) { result.add(""); } result.add(curr.trimstart(',')); } return result.toarray<string>(); }
Comments
Post a Comment