18 Ekim 2011 Salı

String.RemoveMany (Extension Method)

public static string RemoveMany(this string dirtyString, params string[] stringsToRemove)
{
            return dirtyString.Split(stringsToRemove, StringSplitOptions.None)
           .Aggregate((sentence, next) => sentence + next)
}

Kullanımı:
string dirty = "This is ABCa st)r(ing.";
string dirty2 = "tDEFes.t-";
string[] delims = new string[] { "ABC", "(", ")" };
Console.WriteLine(dirty.RemoveMany(delims));
Console.WriteLine(dirty2.RemoveMany("DEF", ".", "-"));
//output
"This is a string."
"test"

Hiç yorum yok:

Yorum Gönder