Except Chars - CSharp System

CSharp examples for System:Char

Description

Except Chars

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;

public class Main{
        public static string ExceptChars(this string str, IEnumerable<char> toExclude)
        {// ww  w.  jav  a2  s.com
            var sb = new StringBuilder(str.Length);
            for (var i = 0; i < str.Length; i++)
            {
                var c = str[i];
                if (!toExclude.Contains(c))
                    sb.Append(c);
            }
            return sb.ToString();
        }
}

Related Tutorials