I'm reading strings from a MySQL database which is not set to Unicode.
The ruby string gets like 渃姧 '<< / code>, but I know that the correct version should be
七 大洋
. The "incorrect" string has been encoded as UTF-8 because Ruby does not know that it is wrong. I tried to force every encoding on Mars string but nothing works, I think I can do it by neutralizing it, but I do not even know where it is starting from.
I do not think any information has been lost because the wrong string is actually more bytes compared to the correct one. I do not think that Ruby is a criminal here because the string is also ruby Seeing the outside table seems confused - so I'm hoping to undo the damage that MySQL has already done.
You can use the following build to return encoding:
"wrong_string" .encode (encoding :: SOME_ENCODING) .force_encoding ('Utf-8')
I tried all possible encoding to find the right encoding:
encoding.constants.each_with_object ({}) do Encoding_name, results | Value = "七姧 '<". Encoding (encoding.config_gate encoding_name) .force_encoding ('utf-8') Rescue zero result [encoding_name] = value value == "七 大洋" end.keys # = & gt; [: Windows_1252 ,: WINDOWS_1252 ,: CP1252 ,: Windows_1254 ,: WINDOWS_1254, CP1254]
Thus, to convert your string to 七 大洋
You can use any encoding from above.
Comments
Post a Comment