I\'d like to write an extension method for the .NET String class. I\'d like it to be a special varation on the Split method - one that takes an escape character to prevent s
public static string[] Split(this string input, string separator, char escapeCharacter)
{
Guid g = Guid.NewGuid();
input = input.Replace(escapeCharacter.ToString() + separator, g.ToString());
string[] result = input.Split(new string []{separator}, StringSplitOptions.None);
for (int i = 0; i < result.Length; i++)
{
result[i] = result[i].Replace(g.ToString(), escapeCharacter.ToString() + separator);
}
return result;
}
Probably not the best way of doing it, but it's another alternative. Basically, everywhere the sequence of escape+seperator is found, replace it with a GUID (you can use any other random crap in here, doesn't matter). Then use the built in split function. Then replace the guid in each element of the array with the escape+seperator.