I guess that everyone whom comes from Czech or Slovakia or at least works there needs remove diacritics time to time. Actually there is quite easy solution for this:
// using System.Globalization
public static string RemoveDiacritics(string s) {
s = s.Normalize(NormalizationForm.FormD);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.Length; i++) {
if (CharUnicodeInfo.GetUnicodeCategory(s[i]) != UnicodeCategory.NonSpacingMark) sb.Append(s[i]);
}
return sb.ToString();
}
I won't describe the solution here 'cause you can find the original source here http://www.aspnet.cz/articles/92-jak-spolehlive-odstranit-v-net-z-retezce-diakritiku
It's in Czech, but all things are easily to find on the MSDN.
happy codding...
No comments:
Post a Comment