Hello friends, first i have to say: my english is not so good, I'll try
my best. I passed many hours yesterday and a couple of hours today
trying to figure out why my source code isn't displayed as supposed.
I'll show you the code to continue:
1 # encoding: UTF-8
2 puts "¿Cual es tu nombre? áéíóúñ"
3 nombre = gets.chomp
4 puts "¿Cual es tu segundo nombre?"
5 segundonombre = gets.chomp
6 puts "¿Cual es tu apellido?"
7 apellido = gets.chomp
8 puts "Hola " + nombre + " " + segundonombre + " " + apellido +\
9 "!! Un gustaso conocerte!! :)"
*************************The trouble*******************************
I save this program as something.rb, and then execute it with require
'something'. I putted some characters like áéíóúñ¿ to show up in the
ruby prompt, is supposed that ruby will show me this: ¿Cual es tu
nombre? áéíóúñ, but Ruby show me crabbed characters instead of áéíóúñ¿.
A few things to say:
1) I'm running Windows SP3 in my PC. I have used Komodo and InType
(IDEs), and with both is the same result. I have tryied many ways: I
saved the file with UTF-8, ISO-8859-1 and variants and always the same
result.
2) I've added puts __ENCODING__ in the middle of the source code to see
if ruby was getting the mean of the first line of the code, and it was
good, Ruby gives: UTF-8, but still show me strange characters.
3) I`ve re-instaled Ruby, old 1.9 versions and it the same, I don't
want to have to run Ruby 1.8, reading i found that this is a trouble of
1.9 ver..
4) Running the program:
require 'anything'
┐┐Cual es tu nombre? ├í├®├¡├│├║├▒
=> Ñàácaró
┐┐Cual es tu segundo nombre?
=> Úúúlñ
┐┐Cual es tu apellido?
=> ¿¿¿¿¿¿ñá
Hola Ñàácaró Úúúlñ ¿¿¿¿¿¿ñá!! Un gustaso conocerte!!
# Observe that when I write in the prompt characters with ´ or ` or ¿
#or ñ Ruby take it fine, i mean, it don't respond me with strange
#characters.
5) Strange things that I've found in Ruby about this trouble:
puts __ENCODING__
=> CP850 # CP850 is the Latin-1 encoding
"ñññññ"
=> "\xA4\xA4\xA4\xA4\xA4"
puts "ñññññ"
=> ñññññ
"ñññññ".force_encoding("CP850")
=> "\xA4\xA4\xA4\xA4\xA4"
"ñññññ".force_encoding("UTF-8")
=> "\xA4\xA4\xA4\xA4\xA4"
"ñññññ".force_encoding("ISO-8859-1") # ISO-8859-1 is the Latin-1\
#encoding
=> "ñññññ"
I will be very grateful with your help, thanks.
···
--
Posted via http://www.ruby-forum.com/.