I need a method that removes a list of characters from a string. I need to support properly all characters but I'm not sure I'm managing surrogate characters properly.
Is there any better way?
public static string Remove(string source, char[] oldChar)
{
if (string.IsNullOrEmpty(source) || oldChar == null || oldChar.Length == 0)
return source;
for (int i = source.IndexOfAny(oldChar, 0); i != -1; i = source.IndexOfAny(oldChar, i))
source = source.Remove(i, char.IsSurrogatePair(source, i) ? 2 : 1);
return source;
}
Thank you
Frank
charvalue anyway... perhaps your second argument should beint[]?