Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. static string[] MyRun(string row, char delimiter)
  2. {
  3. row = row.TrimEnd();
  4. int length = row.Length;
  5. string[] myResult = new string[300];
  6. var myArray = row.ToCharArray();
  7.  
  8. var inQuite = false;
  9. var quoteFound = false;
  10. int count = 0;
  11. int exit = 0;
  12. int countColumn = 1;
  13. int secondCount = 0;
  14.  
  15. if (row[0] == '"')
  16. {
  17. quoteFound = true;
  18. count++;
  19. }
  20.  
  21. if (quoteFound == true)
  22. {
  23. for (int i = 0; i < length; i++)
  24. {
  25. if (i == 2)
  26. {
  27.  
  28. }
  29. if (row[i] == '"')
  30. {
  31. count++;
  32. if (i + 1 < length)
  33. {
  34. if (row[i + 1] == delimiter) exit++;
  35. }
  36. inQuite = true;
  37. }
  38. else
  39. {
  40. if (row[i] == delimiter && count % 2 == 1 && inQuite == true)
  41. {
  42. secondCount++;
  43. countColumn++;
  44. }
  45. count = 1;
  46.  
  47. }
  48. if (i > 1 && row[i - 1] == '"' && row[i] == delimiter)
  49. {
  50. if (myResult[secondCount] != null)
  51. {
  52. secondCount++;
  53. countColumn++;
  54. inQuite = false;
  55. }
  56. }
  57. if (count % 2 != 0 && inQuite == true)
  58. {
  59. myResult[secondCount] += row[i];
  60. }
  61. else if (count % 2 != 0 && inQuite == false && row[i] != delimiter)
  62. {
  63. myResult[secondCount] += row[i];
  64. }
  65. else if (inQuite == true && row[i] == '"')
  66. {
  67. myResult[secondCount] += row[i];
  68. }
  69. if (exit == 2)
  70. {
  71. inQuite = false;
  72. exit = 0;
  73. }
  74. }
  75. }
  76. else
  77. {
  78. return row.Split(delimiter);
  79. }
  80. var result = new string[countColumn];
  81. for (int i = 0; i < countColumn; i++)
  82. {
  83. if (myResult[i] == null)
  84. {
  85. myResult[i] = "";
  86. }
  87. result[i] = myResult[i];
  88. }
  89. return result;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement