如从字符串this is an apple删除aeiou字符
输出:ths s n ppl
具体代码: static string RemoveChars(string str, string remove) { if(string.IsNullOrEmpty(str) || string.IsNullOrEmpty(remove)) { throw new ArgumentException("...."); } StringBuilder result = new StringBuilder(str.Length); Dictionary<char, bool> dictionary = new Dictionary<char, bool>(); foreach(char ch in remove) { dictionary[ch] = true; } foreach(char ch in str) { if(!dictionary.ContainsKey(ch)) { result.Append(ch); } } return result.ToString(); } |