I was having a little problem writing a "url friendly" for this site, since some of the blog will be in Vietnamese and I don't want to have all those special accent marks on it. (For examle, "tôi yêu tiếng nước tôi, từ khi mới ra đời, người ơi...", it should be just "toi yeu tieng nuoc toi, tu khi moi ra doi, nguoi oi" for a friendly, readily by the browser.) So this is the code to remove all the accent marks:
public static string removeAccents(string stIn)
{
string stFormD = stIn.Normalize(NormalizationForm.FormD);
StringBuilder sb = new StringBuilder();
for (int ich = 0; ich < stFormD.Length; ich++)
{
UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]);
if (uc != UnicodeCategory.NonSpacingMark)
{
sb.Append(stFormD[ich]);
}
}
return (sb.ToString().Normalize(NormalizationForm.FormC));
}But for the life of me, I can't understand why this character's accent mark can't be removed: đ and Đ. So what I did was just to do a replace at the return, so the last line should be:
return (sb.ToString().Normalize(NormalizationForm.FormC)).Replace("đ", "d").Replace("Đ", "D");
If you know a better way or a different solution, please share :) That is it for now, I will post another post on how to do friendly url on your mvc site.