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

DeleteChars

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

Source

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

Example

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: 5432