Removing/replacing international characters

前端 未结 2 1828
栀梦
栀梦 2021-01-01 02:31

I am creating a small app in C# to search for filenames based on information passed from a SQL query. Within the data passed from the SQL query there will be on occasion (po

2条回答
  •  醉梦人生
    2021-01-01 02:42

    var s1 = ToASCII("Hervé");
    var s2 = ToASCII("Mañana"); 
    
    string ToASCII(string s)
    {
        return String.Join("",
             s.Normalize(NormalizationForm.FormD)
            .Where(c => char.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark));
    }
    

提交回复
热议问题