3 ms·
The problem is in your input handling. You are getting latin-1 value for the (tm) sign (\x99, decimal 156), and you are treating that as if it was some unicode
by euccastro 19y ago
The problem is in your input handling. You are getting latin-1 value for the (tm) sign (\x99, decimal 156), and you are treating that as if it was some unicode code point 156, which AFAIK is nonsense.
When you try to encode that bogus thing in utf-8 you get \xc3\x99, which in latin-1 is A-with-circumflex followed by the TM sign, while in utf-8 it's still nonsense.
What you need to do is decode your input from the remote system encoding into your native unicode representation, before encoding it in utf-8 to display it.
The first problem is detecting the native encoding at the other end. I don't know how to do this, but if you assume latin-1 to begin with, it will still be an improvement over the current situation.
Once you know/guess the encoding, you normalize it with something like this (in mzScheme):
(bytes->string/latin-1 remote-txt)
Then you convert to utf-8 like this (you are already doing this):
(string->bytes/utf-8 stored-string)
Finally, remember to put back the meta tag.
HTH.