C
C# Learner
Hi,
I have a string (System.String) which holds some data. This data is
encoding in UTF8 (i.e. anywhere in the string where there should be a
single 'é' character, there will be two characters holding the
equivalent of that character in the UTF8 format).
How can I decode this UTF8-encoded string?
In Delphi I could simple say:
myString = UTF8ToAnsi(myString);
How can I do this using .NET?
I tried making a general-purpose static method to do this:
private static string Utf8ToAscii(string value)
{
byte[] utf8Bytes = Encoding.UTF8.GetBytes(value);
byte[] asciiBytes = Encoding.Convert(Encoding.UTF8,
Encoding.Unicode, utf8Bytes);
return Encoding.Unicode.GetString(asciiBytes);
}
....but it doesn't work as desired. This just causes the pair of
encoded characters to be replaced to '?' characters.
TIA
I have a string (System.String) which holds some data. This data is
encoding in UTF8 (i.e. anywhere in the string where there should be a
single 'é' character, there will be two characters holding the
equivalent of that character in the UTF8 format).
How can I decode this UTF8-encoded string?
In Delphi I could simple say:
myString = UTF8ToAnsi(myString);
How can I do this using .NET?
I tried making a general-purpose static method to do this:
private static string Utf8ToAscii(string value)
{
byte[] utf8Bytes = Encoding.UTF8.GetBytes(value);
byte[] asciiBytes = Encoding.Convert(Encoding.UTF8,
Encoding.Unicode, utf8Bytes);
return Encoding.Unicode.GetString(asciiBytes);
}
....but it doesn't work as desired. This just causes the pair of
encoded characters to be replaced to '?' characters.
TIA