0
我需要一种从字符串中删除字符列表的方法。我需要正确支持所有角色,但我不确定我是否正确地管理代理角色。删除C#中字符串的字符列表#
有没有更好的方法?
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;
}
谢谢
弗兰克
不好怎么办你*想*支持代理对?因为无论如何,你不能在单个“char”值中表示一个非BMP字符......也许你的第二个参数应该是“int []”? –
请提供您期望的样品输入/输出。 –