File encodings with ruby

Posted by pablorc on Stack Overflow See other posts from Stack Overflow or by pablorc
Published on 2010-05-28T12:17:48Z Indexed on 2010/05/28 13:02 UTC
Read the original article Hit count: 193

Filed under:
|

Hi, I'm having a bit problems with file encodings.

I'm receiving a url-encoded string like "sometext%C3%B3+more+%26+andmore", unescape it, process the data, and save it with windows-1252 encoding.

The conversions are these:

irb(main) >> value
=> "sometext%C3%B3+more+%26+andmore"
irb(main) >> CGI::unescape(value)
=> "sometext\303\263 more & andmore"
irb(main) >> #Some code and saved into a file using open(filename, "w:WINDOWS-1252")
irb(main) >> # result in the file:
=> sometextA³ more & andmore

And the result should be sometextó more & andmore

© Stack Overflow or respective owner

Related posts about ruby

Related posts about file-encodings