Skip to content

split comma 2

June 25, 2013
publicstaticIEnumerable<string>SplitCSV(string csvString){var sb =newStringBuilder();
    bool quoted =false;foreach(char c in csvString){if(quoted){if(c =='"')
                quoted =false;else
                sb.Append(c);}else{if(c =='"'){
                quoted =true;}elseif(c ==','){
                yield return sb.ToString();
                sb.Length=0;}else{
                sb.Append(c);}}}if(quoted)thrownewArgumentException("csvString","Unterminated quotation mark.");

    yield return sb.ToString();}
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: