ExtensionMethod.NET Home of 828 C#, Visual Basic, F# and Javascript extension methods


Remove from the given string, all characters provided in a params array of chars.


public static string DeleteChars(this string input, params char[] chars) {
 return new string(input.Where((ch) => !chars.Contains(ch) ).ToArray());


string Text = "#Hello world.  This is a [test]";
string cleanText1 = Text.DeleteChars('#', '[', ']');  //return Hello world.  This is a test 
string cleanText2 = Text.DeleteChars('#');
//return Hello world.  This is a [test]

Author: Érico Luis Barrientos Leite

Submitted on: 14 jan 2012

Language: C#

Type: System.String

Views: 3567