Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

NameException

Encoding

Recommended Posts

NameException

Boa tarde,

Estou com dificuldade em escrever texto na codificação correcta, em ruby.

Exemplo:

text = "olá"
puts text

Output: olá

Podem ajudar?

Obrigado

Share this post


Link to post
Share on other sites
NameException

Olá Rui,

Na consola de windows:

C:\>chcp
Active code page: 437

Estou a utilizar a versão de ruby 1.8.6, que utiliza o encoding UTF-8.

O problema está em fazer a conversão entre estes encodings...

:wallbash:

Share this post


Link to post
Share on other sites
NameException

Boa tarde,

Partilho aqui o que procurava:

class String
  require 'iconv' 
  def to_iso
    Iconv.conv('ISO-8859-1', 'utf-8', self)
  end
end

Cumprimentos

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.