Forum: Ruby How to resolve mixed character Encodings in ruby?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
ms z (Guest)
on 2013-11-06 08:30
(Received via mailing list)
I'm learning ruby and try to get the filename from a ftp server. The
I got was encoded in *gb2312(simplified Chinese)*, It's success in most
cases with these codes:

str = str.force_encoding("gb2312")
str = str.encode("utf-8")

but it will make an error "in encode': "\xFD" followed by "\x88" on
(Encoding::InvalidByteSequenceError)" if the string contains the symbol
 or "【".

Then I use


to detect if all filename strings were encoded by gb2312, some of them
return false. I think I must deal with a string list that's in mixed
character encodings. Help me! Thank you!
This topic is locked and can not be replied to.