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
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));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With