Skip to content

Instantly share code, notes, and snippets.

@andy01pr
Last active December 17, 2022 00:27
Show Gist options
  • Save andy01pr/0cda1cc2ed948cff96da86319c69b0f1 to your computer and use it in GitHub Desktop.
Save andy01pr/0cda1cc2ed948cff96da86319c69b0f1 to your computer and use it in GitHub Desktop.
How to remove or Latinize diacritics/accents in C# (.NET Framework)
using System.Text;
namespace LatinizeExample
{
internal class Program
{
private static void Main(string[] args)
{
//If using .NET Core
//add the Nuget library System.Text.Encoding.CodePages and then
//register the provider at the start of the application
//Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Console.WriteLine("crème brûléeĆČ Leoš Janácek Dvořák".Latinize());
Console.ReadLine();
}
}
public static class StringExtensions
{
private static readonly Encoding latinizeEncoding = Encoding.GetEncoding("ISO-8859-8");
public static string Latinize(this string value)
{
var strBytes = latinizeEncoding.GetBytes(value);
return latinizeEncoding.GetString(strBytes);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment