Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing/replacing international characters

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 (possibly multiple instances due to international visitors to my company) names with international characters within them. The filenames we have are in the english alphabet with no special characters.

I am trying to find a way to convert international characters to pure english alphabet characters so that I can complete this search? Could this be accomplished through the db query or will it have to be done through the app code?

For example:

Hervé needs to be converted to Herve

Or

Mañana needs to be converted to Manana

like image 578
mattgcon Avatar asked Dec 07 '12 18:12

mattgcon


1 Answers

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));
}
like image 179
L.B Avatar answered Sep 21 '22 04:09

L.B