Created
November 10, 2022 06:29
-
-
Save theilgaz/5e45af4ba530be9faa671974d147ea89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static string RemoveDiacritics(this string text) | |
{ | |
Encoding srcEncoding = Encoding.UTF8; | |
Encoding destEncoding = Encoding.GetEncoding(1252); | |
text = destEncoding.GetString(Encoding.Convert(srcEncoding, destEncoding, srcEncoding.GetBytes(text))); | |
string normalizedString = text.Normalize(NormalizationForm.FormD); | |
StringBuilder result = new StringBuilder(); | |
for (int i = 0; i < normalizedString.Length; i++) | |
{ | |
if (!CharUnicodeInfo.GetUnicodeCategory(normalizedString[i]).Equals(UnicodeCategory.NonSpacingMark)) | |
{ | |
result.Append(normalizedString[i]); | |
} | |
} | |
return result.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment