private static string[] Split(string s, string separator)
{
List<string> list = new List<string>(2);
StringBuilder sb = new StringBuilder();
int pos = 0, end = s.Length;
while (pos < end)
{
//if (s.StartsWith(separator, pos))
if (s.Substring(pos).StartsWith(separator))
{
if (sb.Length > 0)
{
list.Add(sb.ToString());
sb = new StringBuilder();
}
pos += separator.Length;
continue;
}
char ch = s[pos++];
if (ch == '\\')
{
sb.Append(ch);
if (pos >= end) // ERROR, or let it go?
{
break;
}
ch = s[pos++];
}
sb.Append(ch);
}
if (sb.Length > 0)
{
list.Add(sb.ToString());
}
return list.ToArray();
}