My flutter app retrieves information via a REST interface which can contain Extended ASCII characters e.g. e-acute 0xe9. How can I convert this into UTF-8 (e.g 0xc3 0xa9) so that it displays correctly?
Converting Extended ASCII characters in Dart
1.2k Views Asked by rodders At
3
There are 3 best solutions below
0
On
I was getting confused because sometimes the data contained extended ascii characters and sometimes UTF-8 characters. When I tried doing a UTF-8 decode it baulked at the extended ascii. I fixed it by trying the utf8 decode and catching the error when it is extended ascii, it seems to decode this OK.
0xE9 corresponds to e-acute (é) in the ISO-8859/Latin 1 encoding. (It's one of many possible encodings for "extended ASCII", although personally I associate the term "extended ASCII" with code page 437.)
You can decode it to a Dart
String(which internally stores UTF-16) usingLatin1Codec. If you really want UTF-8, you can encode thatStringto UTF-8 afterward withUtf8Codec.