Click here to Skip to main content
Click here to Skip to main content

A small CSV Splitter in C#

, 7 Oct 2010
Rate this:
Please Sign up or sign in to vote.
Gives splitted values taking csv string as input.
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)

About the Author

Mahendra Kumar Srivastava
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 Pinmembermstr89911-Oct-10 2:15 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 7 Oct 2010
Article Copyright 2010 by Mahendra Kumar Srivastava
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid