Reputation: 4858
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
Upvotes: 6
Views: 2612
Reputation: 116188
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));
}
Upvotes: 15
Reputation: 1
If you're running against MS-SQL server, see COLLATE in the online help. You can functionally change the encoding on the fly.
Upvotes: 0