public static string TrimEndNotIn(this string text, IList<char> chars) { if (string.IsNullOrWhiteSpace(text)) return text == null ? null : string.Empty; while (text.Length > 1 && !chars.Contains(text[text.Length - 1])) { text = text.Substring(0, text.Length - 1); } if (text.Length == 1 && !chars.Contains(text[0])) return string.Empty; return text; }