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

RemoveSpecialChar

Find and remove any special char, only letting numbers and letters in.

Source

public static string RemoveSpecialChars(this string input) => input == null ? null : Regex.Replace(input, @"[^0-9a-zA-Z]", " ");

Example

Console.Writeline("Clean@This_For Test:".RemoveSpecialChar());

Result: "Clean This For Test"

Author: Sparkymod

Submitted on: 4 jul. 2021

Language: csharp

Type: System.Text.RegularExpressions

Views: 2908