Monday, February 15, 2016

Cách chuyển tiếng Việt có dấu thành không dấu nhanh, gọn, lẹ

Sử dụng RegularExpression, ta có thể khử dấu tiếng Việt một cách nhanh, gọn, lẹ như sau:

public static string convertToUnSign3(string s)
{
    Regex regex = new Regex("\\p{IsCombiningDiacriticalMarks}+");
    string temp = s.Normalize(NormalizationForm.FormD);
    return regex.Replace(temp, String.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D');
}

No comments: