Candor.StringExtensions.TrimEndNotIn C# (CSharp) Method

TrimEndNotIn() public static method

Trims any characters from the end of a string that is not in the supplied list.
public static TrimEndNotIn ( this text, IList chars ) : string
text this The text to be scanned.
chars IList The characters to be kept, such as a LexicalCharacterSet characters list.
return string
        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;
        }