Skip to content

Instantly share code, notes, and snippets.

@thanhhh
Created December 19, 2015 07:48
Show Gist options
  • Save thanhhh/b81d5e48a9b14f1c57e9 to your computer and use it in GitHub Desktop.
Save thanhhh/b81d5e48a9b14f1c57e9 to your computer and use it in GitHub Desktop.
Clear Vietnamese Sign C#
public class StringUtil
{
private static readonly string[] VietnameseSigns = new string[]
{
"aAeEoOuUiIdDyY",
"áàạảãâấầậẩẫăắằặẳẵ",
"ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ",
"éèẹẻẽêếềệểễ",
"ÉÈẸẺẼÊẾỀỆỂỄ",
"óòọỏõôốồộổỗơớờợởỡ",
"ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ",
"úùụủũưứừựửữ",
"ÚÙỤỦŨƯỨỪỰỬỮ",
"íìịỉĩ",
"ÍÌỊỈĨ",
"đ",
"Đ",
"ýỳỵỷỹ",
"ÝỲỴỶỸ"
};
public static string RemoveSign4VietnameseString(string str)
{
//Tiến hành thay thế , lọc bỏ dấu cho chuỗi
for (int i = 1; i < VietnameseSigns.Length; i++)
{
for (int j = 0; j < VietnameseSigns[i].Length; j++)
str = str.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]);
}
return str;
}
}
@Smilefounder
Copy link

image

@trungnam003
Copy link

trungnam003 commented Nov 30, 2023

Xóa dấu tiếng việt dùng regex

public static partial class StringUtils
{
    public static string RemoveSign4VietnameseString(string s)
    {
        Regex regex = IsCombiningDiacriticalMarksRegex();
        string temp = s.Normalize(NormalizationForm.FormD);
        return regex.Replace(temp, string.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D');
    }

    [GeneratedRegex("\\p{IsCombiningDiacriticalMarks}+")]
    private static partial Regex IsCombiningDiacriticalMarksRegex();
}

2024-04-22 Trung Nam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment