Return to Snippet

Revision: 43042
at March 15, 2011 19:58 by Krummelz


Initial Code
public static string[] SanitizeSplit(string s, string seperator)
        {
            List<string> result = new List<string>();
            bool mustSplit = true;

            string currentWord = string.Empty;

            for (int i = 0; i < s.Length; i++)
            {
                string l = s.Substring(i, 1);

                if ((l == "'" || l == "\"") && mustSplit)
                {
                    mustSplit = false;
                    continue;
                }

                if ((l == "'" || l == "\"") && !mustSplit)
                {
                    mustSplit = true;
                    continue;
                }

                if (l != seperator || (l == seperator && !mustSplit))
                    currentWord += l;
                else
                {
                    result.Add(currentWord.Trim());
                    currentWord = string.Empty;
                }
            }
            result.Add(currentWord);
            return result.ToArray();
        }

Initial URL

                                

Initial Description
it ignores commas in a csv that are in string quotes

Initial Title
Method to import MySQL Scripts to MS SQL

Initial Tags
mysql

Initial Language
C#