Method to import MySQL Scripts to MS SQL


/ Published in: C#
Save to your folder(s)

it ignores commas in a csv that are in string quotes


Copy this code and paste it in your HTML
  1. public static string[] SanitizeSplit(string s, string seperator)
  2. {
  3. List<string> result = new List<string>();
  4. bool mustSplit = true;
  5.  
  6. string currentWord = string.Empty;
  7.  
  8. for (int i = 0; i < s.Length; i++)
  9. {
  10. string l = s.Substring(i, 1);
  11.  
  12. if ((l == "'" || l == "\"") && mustSplit)
  13. {
  14. mustSplit = false;
  15. continue;
  16. }
  17.  
  18. if ((l == "'" || l == "\"") && !mustSplit)
  19. {
  20. mustSplit = true;
  21. continue;
  22. }
  23.  
  24. if (l != seperator || (l == seperator && !mustSplit))
  25. currentWord += l;
  26. else
  27. {
  28. result.Add(currentWord.Trim());
  29. currentWord = string.Empty;
  30. }
  31. }
  32. result.Add(currentWord);
  33. return result.ToArray();
  34. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.