I want to automatically convert UTF-8 characters like â Ù á Č Ģ
to a U a C G
so that they would be acceptable in a URL.
So far I have this:
Encoding sourceEncoding = Encoding.GetEncoding(28591); // ISO-8859-1
byte[] asciiBytes = Encoding.Convert(sourceEncoding, Encoding.ASCII, sourceEncoding.GetBytes(<source text>));
String asciiString = Encoding.UTF8.GetString(asciiBytes);
Two problems with this approach:
- This works fine for some characters (Č and Ģ), but for others (â, Ù, á) it returns a question mark in place of the character.
- The whole site is in UTF-8, not ISO-8859-1, but when I set sourceEncoding to Encoding.UTF8 all of the characters are converted to question marks, so it doesn't work at all.
Got any ideas how I could make this work?