Hi folks,
First post here, thanks for the help.
Having a strange behavior with my ruby 1.9.2 code. When i try to print
latin characters with accents, i get the follow error:
incompatible character encodings: UTF-8 and
IBM437
Code follows bellow and a screen shot attached:
-----------BEGIN OF CODE--------
# encoding: UTF-8
# Html Inspect
# Ler uma página html
# Calcular o número de linhas
# Calcular o número de palavras
# Calcular o número de caracteres
# Encontrar o Título da Página
# Encontrar os Sub-Títulos
# Exibir um resumo sobre a página
arquivo = File.readlines("pagina.html")
linhas = arquivo.size
pagina = arquivo.join
quantidade_palavras = pagina.split.length
quantidade_caracteres = pagina.length
titulo = []
arquivo.each do |line|
if line.match(/<title>/)
titulo << line
end
end
puts "#{linhas} linhas"
puts "#{quantidade_palavras} palavras"
puts "#{quantidade_caracteres} caracteres"
puts "Título: #{titulo.join}"
----------END OF CODE----------
----------BEGIN OF OUTPUT------
C:\Ruby192\bin\ruby.exe -e $stdout.sync=true;
$stderr.sync=true;load($0=ARGV.shift) C:/Users/Sandbox.Marco-PC/
RubymineProjects/TempApp/main.rb
C:/Users/Sandbox.Marco-PC/RubymineProjects/TempApp/main.rb:25:in `<top
(required)>': incompatible character encodings: UTF-8 and IBM437
(Encoding::CompatibilityError)
from -e:1:in `load'
from -e:1:in `<main>'
1483 linhas
25939 palavras
354934 caracteres
Process finished with exit code 1
--------END OF OUTPUT----------
Attachments:
http://www.ruby-forum.com/attachment/6525/ruby_enconding_error.JPG
···
--
Posted via http://www.ruby-forum.com/.