Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static string[] MyRun(string row, char delimiter)
- {
- row = row.TrimEnd();
- int length = row.Length;
- string[] myResult = new string[300];
- var myArray = row.ToCharArray();
- var inQuite = false;
- var quoteFound = false;
- int count = 0;
- int exit = 0;
- int countColumn = 1;
- int secondCount = 0;
- if (row[0] == '"')
- {
- quoteFound = true;
- count++;
- }
- if (quoteFound == true)
- {
- for (int i = 0; i < length; i++)
- {
- if (i == 2)
- {
- }
- if (row[i] == '"')
- {
- count++;
- if (i + 1 < length)
- {
- if (row[i + 1] == delimiter) exit++;
- }
- inQuite = true;
- }
- else
- {
- if (row[i] == delimiter && count % 2 == 1 && inQuite == true)
- {
- secondCount++;
- countColumn++;
- }
- count = 1;
- }
- if (i > 1 && row[i - 1] == '"' && row[i] == delimiter)
- {
- if (myResult[secondCount] != null)
- {
- secondCount++;
- countColumn++;
- inQuite = false;
- }
- }
- if (count % 2 != 0 && inQuite == true)
- {
- myResult[secondCount] += row[i];
- }
- else if (count % 2 != 0 && inQuite == false && row[i] != delimiter)
- {
- myResult[secondCount] += row[i];
- }
- else if (inQuite == true && row[i] == '"')
- {
- myResult[secondCount] += row[i];
- }
- if (exit == 2)
- {
- inQuite = false;
- exit = 0;
- }
- }
- }
- else
- {
- return row.Split(delimiter);
- }
- var result = new string[countColumn];
- for (int i = 0; i < countColumn; i++)
- {
- if (myResult[i] == null)
- {
- myResult[i] = "";
- }
- result[i] = myResult[i];
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement