Advertisement
Guest User

Untitled

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