Click here to Skip to main content
15,881,882 members
Articles / General Programming / Regular Expressions
Tip/Trick

A small CSV Splitter in C#

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
7 Oct 2010CPOL 14.2K   1   1
Gives splitted values taking csv string as input.
C#
public string[] SplitCSVString(string csvString)
        {
            // CSV Reg Ex: ",(?!(?<=(?:^|,)\s*\x22(?:[^\x22]|\x22\x22|\\x22)*,)(?:[^\x22]|\x22\x22|\\x22)*\x22\s*(?:,|$))"
            string strPattern = ",(?!(?<=(?:^|,)\\s*\\x22(?:[^\\x22]|\\x22\\x22|\\\\x22)*,)(?:[^\\x22]|\\x22\\x22|\\\\x22)*\\x22\\s*(?:,|$))";
            System.Text.RegularExpressions.Regex csvSplitter = new System.Text.RegularExpressions.Regex(strPattern);
            return csvSplitter.Split(csvString);
        }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader M*Modal
India India
Started carreer with CEERI, Delhi, India as a C Programmer in 2004 and migrated my learning experiance to C#.Net in 2005 with DIGISIGN Noida, Joined Bally in 2006, worked with JK Technosoft since Jun 2007 till Apr 2009, joined back Bally in June 2009 and joined Misys in June 2010. Worked in different domains such as Casino Management, Digital Signage, and Medical and currently working M*Modal as Lead - Product Development.

Comments and Discussions

 
GeneralReason for my vote of 1 no description Pin
mstr89911-Oct-10 2:15
mstr89911-Oct-10 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.