c# - Importing csv file with commas in it Asp.net -


this question has answer here:

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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -