Hello.

Today I needed a way to split a string in to a list, but also skipping over commas resounded in quotes. so I looked at some old code I did for VB.NET, but found a bug, anyway looked into regex and came across some problems so gave up. then I started a new version from scratch. it's not in anyway full proof but it seems to serve my purpose. anyway I post here in the hope that it maybe us-full. if you find a bug and think you can fix it. please go ahead.

Code


csharp Code:
  1. span style="color: #808080;">'\0'""//Append sep
  2. //Check for quotes
  3. //if char is not seperator and not in quotes add string to list.
  4. //Add to collection.
  5. //Clear the line.
  6. //Prepare string for adding to list.
  7. //INC Counter.
  8.                 x++;
  9.             }
  10.             //Return list.
  11. //No quote string
  12. "one,two,six""'one,two,six',Test with quotes,'10,20'"',', '\'');
  13.  
  14.             MessageBox.Show("Test 1"//Test 2
  15.             lst = Split(Test2, ',', '\'');
  16.  
  17.             MessageBox.Show("Test 2"