Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Problem with special characters
Alejandro Michelin salomon
2/19/2009 1:05:00 PM
Hi:
O.S Windows XP sp3
Ruby 1.8.6
I am working with ruby using DBI::Mysql, and the returned descriptions
are not displayed ok. The puts command is displaying wrong characters,
when the text has special chars like á.
My program here :
puts "Olá Mundo!"; # for test
require "dbi";
begin
# connect to the MySQL server
dbh = DBI.connect("DBI:Mysql:test:localhost", "test",
"q3der3fe5ahy");
sth = dbh.execute("SELECT * FROM uf ");
sth.each do |row|
puts 'ID:' + row[0].to_s + ' Mi: ' + row[1] + 'Decrição: ' +
row[2];
end
sth.finish;
rescue DBI::DatabaseError => e
puts "An error occurred";
puts "Error code: #{e.err}";
puts "Error message: #{e.errstr}";
ensure
# disconnect from server
dbh.disconnect if dbh;
end
//=========== Result
OlÃ? Mundo!
ID:1 Mi: AC Decriþ�o: Acre
ID:2 Mi: AL Decriþ�o: Alagoas
ID:3 Mi: AM Decriþ�o: Amazonas
ID:4 Mi: AP Decriþ�o: Amap�
ID:5 Mi: BA Decriþ�o: Bahia
ID:6 Mi: CE Decriþ�o: Cear�
ID:7 Mi: DF Decriþ�o: Distrito Federal
ID:8 Mi: ES DecriþÃ?o: EspÃrito Santo
ID:9 Mi: GO Decriþ�o: Goi�s
ID:10 Mi: MA Decriþ�o: Maranh�o
ID:11 Mi: MG Decriþ�o: Minas Gerais
ID:12 Mi: MS Decriþ�o: Mato Grosso do Sul
ID:13 Mi: MT Decriþ�o: Mato Grosso
ID:14 Mi: PA Decriþ�o: Par�
ID:15 Mi: PB DecriþÃ?o: ParaÃba
ID:16 Mi: PE Decriþ�o: Pernambuco
ID:17 Mi: PI DecriþÃ?o: PiauÃ
ID:18 Mi: PR Decriþ�o: Paran�
ID:19 Mi: RJ Decriþ�o: Rio de Janeiro
ID:20 Mi: RN Decriþ�o: Rio Grande do Norte
ID:21 Mi: RO Decriþ�o: Rond¶nia
ID:22 Mi: RR Decriþ�o: Roraima
ID:23 Mi: RS Decriþ�o: Rio Grande do Sul
ID:24 Mi: SC Decriþ�o: Santa Catarina
ID:25 Mi: SE Decriþ�o: Sergipe
ID:26 Mi: SP Decriþ�o: S�o Paulo
ID:27 Mi: TO Decriþ�o: Tocantins
ID:28 Mi: XX Decriþ�o: Fora Do Brasil
How to display the text with special characters like 'ç ú Ã' tha are
used commonly in latin languages?
--
Posted via
http://www.ruby-...
.
1 Answer
ThoML
2/19/2009 1:57:00 PM
0
> Decri=E7=E3o
> Decri=FE=D2o
Your input is in latin-1[1] but the windows console probably uses cp850
[2]. You could change the codepage with "mode con cp select=3D1252" (I
guess), use other software, or recode the output.
[1]
http://en.wikipedia.org/wiki/...
[2]
http://en.wikipedia.org/...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Problem with special characters
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password