Пример #1
0
        /// <summary>
        /// Gets a <see cref="string"/> of only the characters that are valid for the specified <see cref="CharType"/>.
        /// </summary>
        /// <param name="validChars">The valid chars.</param>
        /// <param name="inStr">The string to remove the characters from that are not valid for the <paramref name="validChars"/>.</param>
        /// <returns>The <paramref name="inStr"/> minus all characters that were not valid for the <paramref name="validChars"/>.</returns>
        public static string GetValidCharsOnly(this CharType validChars, string inStr)
        {
            if (string.IsNullOrEmpty(inStr))
            {
                return(inStr);
            }

            var output = inStr;

            for (var i = 0; i < output.Length; i++)
            {
                var c = inStr[i];

                if (!validChars.IsValidChar(c))
                {
                    output = output.Remove(i, 1);
                    i--;
                }
            }

            return(output);
        }