Regular expression comes in handy especially if you want to remove the non ascii characters from a string in C#. Here’s a regular expression sample in C# demonstrating how to do it.
How to remove the non ascii characters from a string in C# ?
using System;
namespace AbundantcodeConsoleApp
{
class Program
{
static void Main(string[] args)
{
string input = "Cøde in C#";
input = System.Text.RegularExpressions.Regex.Replace(input, @"[^\u0000-\u007F]+", string.Empty);
Console.WriteLine(input);
Console.ReadLine();
}
}
}The output of the code snippet will be
cde in C#
Leave a Reply