# Encoding in windows (newby question)

**URL:** <https://www.ruby-forum.com/t/encoding-in-windows-newby-question/76251>\
**Category:** Ruby\
**Created:** [November 16, 2006, 11:34pm UTC](https://www.ruby-forum.com/t/encoding-in-windows-newby-question/76251 "2006-11-16T23:34:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 16, 2006, 11:34pm UTC](https://www.ruby-forum.com/t/encoding-in-windows-newby-question/76251/1 "2006-11-16T23:34:11Z")

</div>

When I write my scripts in Linux, there is no problem with the special  
characters, but on windows, the special characters of my language are  
not properly set (spanish). Example puts “español”. I suppose for some  
reason ruby detects the correct charset in linux but not in windows.  
Could anyone say what is the reason for that, and the procedure to solve  
it?

Thanks in advance.

* * *

LLama Gratis a cualquier PC del Mundo.  
Llamadas a fijos y móviles desde 1 céntimo por minuto.  
[http://es.voice.yahoo.com](http://es.voice.yahoo.com)

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 17, 2006, 12:22am UTC](https://www.ruby-forum.com/t/encoding-in-windows-newby-question/76251/2 "2006-11-17T00:22:26Z")

</div>

Alfonso wrote:

> When I write my scripts in Linux, there is no problem with the special  
> characters, but on windows, the special characters of my language are  
> not properly set (spanish).

Define “not properly set.” Leave nothing to the imagination. What did  
you  
expect, and what did you get, under what circumstances?

> Example puts “espaÃ±ol”. I suppose for some  
> reason ruby detects the correct charset in linux but not in windows.  
> Could anyone say what is the reason for that, and the procedure to solve  
> it?

The answer depends on where this happened, using what output device or  
editor, etc, etc…

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 17, 2006, 1:06am UTC](https://www.ruby-forum.com/t/encoding-in-windows-newby-question/76251/3 "2006-11-17T01:06:37Z")

</div>

Paul L. escribiÃ³:

> > Example puts “espaÃ±ol”. I suppose for some  
> > reason ruby detects the correct charset in linux but not in windows.  
> > Could anyone say what is the reason for that, and the procedure to solve  
> > it?
> 
> The answer depends on where this happened, using what output device or  
> editor, etc, etc…

I have tried this in two different computers with windows xp spanish  
version installed. If I use the interactive console and write, for  
example this line:

puts “Ã± Ã³ Ã¡ Ã© Ã­”

then after presing enter, the result will be this: Ã± Ã³ Ã¡ Ã© Ã­

Now, if I write the same with a text editor (I use vim, but have tried  
also with notepad), this is the result: Â± Â¾ ÃŸ Ãš Ã

As opposite, in linux, the result is allways Ã± Ã³ Ã¡ Ã© Ã­.

* * *

LLama Gratis a cualquier PC del Mundo.  
Llamadas a fijos y móviles desde 1 céntimo por minuto.  
[http://es.voice.yahoo.com](http://es.voice.yahoo.com)

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 17, 2006, 1:20am UTC](https://www.ruby-forum.com/t/encoding-in-windows-newby-question/76251/4 "2006-11-17T01:20:39Z")

</div>

Alfonso wrote:

/ …

> Now, if I write the same with a text editor (I use vim, but have tried  
> also with notepad), this is the result: Â± Â¾ ÃŸ Ãš Ã

You need to obtain a font that is appropriate to the language you are  
using.  
I want to emphasize that the characters in the file are very likely to  
be  
correct, but their representation on the display is the only problem,  
and  
that is a font issue.

In Windows, you have the option of changing locales, or installing an  
appropriate font, or both. Specifically with regard to either Notepad or  
VIM, see if you have the option of changing the editing font.

> As opposite, in linux, the result is allways Ã± Ã³ Ã¡ Ã© Ã­.

Linux is typically (but not always) more aware of locale issues. An  
example  
is the fact that I am getting the correct accented character  
representations here on Fedora 5’s newsreader, and I doubt that I would  
on  
a recent Windows version.

But again, it’s very likely that the characters are correct, only their  
display is wrong.

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 17, 2006, 1:34am UTC](https://www.ruby-forum.com/t/encoding-in-windows-newby-question/76251/5 "2006-11-17T01:34:41Z")

</div>

Paul L. escribiÃ³:

> > version installed. If I use the interactive console and write, for  
> > You need to obtain a font that is appropriate to the language you are using.
> 
> Linux is typically (but not always) more aware of locale issues. An example  
> is the fact that I am getting the correct accented character  
> representations here on Fedora 5’s newsreader, and I doubt that I would on  
> a recent Windows version.
> 
> But again, it’s very likely that the characters are correct, only their  
> display is wrong.

Sorry, I didn’t expressed me correctly. When I said that if I type Ã± Ã³ Ã¡  
Ã© Ã­ in the editor I have this result

Â± Â¾ ÃŸ Ãš Ã. I didn’t mean that I couldn’t see Ã± Ã³ Ã¡ Ã© Ã­ in the  
edited file. They appear just so: Ã± Ã³ Ã¡ Ã© Ã­. The problem is after  
executing the program (“ruby myprogram.rb”). Then the result in the  
console will be this: Â± Â¾ ÃŸ Ãš Ã. But the saved file has no problem with  
representation…

* * *

LLama Gratis a cualquier PC del Mundo.  
Llamadas a fijos y móviles desde 1 céntimo por minuto.  
[http://es.voice.yahoo.com](http://es.voice.yahoo.com)

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 17, 2006, 6:27am UTC](https://www.ruby-forum.com/t/encoding-in-windows-newby-question/76251/6 "2006-11-17T06:27:09Z")

</div>

Alfonso wrote:

/ …

> Sorry, I didn’t expressed me correctly. When I said that if I type Ã± Ã³ Ã¡  
> Ã© Ã­ in the editor I have this result
> 
> Â± Â¾ ÃŸ Ãš Ã. I didn’t mean that I couldn’t see Ã± Ã³ Ã¡ Ã© Ã­ in the edited  
> file. They appear just so: Ã± Ã³ Ã¡ Ã© Ã­. The problem is after executing the  
> program (“ruby myprogram.rb”). Then the result in the console will be  
> this: Â± Â¾ ÃŸ Ãš Ã. But the saved file has no problem with representation…

Then the problem is most likely the console font. Same remedy – change  
fonts. Nearly all these sorts of problems are caused by using the wrong  
font.

But if you want to distinguish between font issues and others, capture  
the  
output of your program and load it into your editor, to confirm that the  
characters appear correctly there.

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 17, 2006, 9:21am UTC](https://www.ruby-forum.com/t/encoding-in-windows-newby-question/76251/7 "2006-11-17T09:21:23Z")

</div>

Alfonso schrieb:

> Sorry, I didn’t expressed me correctly. When I said that if I type Ã± Ã³ Ã¡  
> Ã© Ã­ in the editor I have this result
> 
> Â± Â¾ ÃŸ Ãš Ã. I didn’t mean that I couldn’t see Ã± Ã³ Ã¡ Ã© Ã­ in the  
> edited file. They appear just so: Ã± Ã³ Ã¡ Ã© Ã­. The problem is after  
> executing the program (“ruby myprogram.rb”). Then the result in the  
> console will be this: Â± Â¾ ÃŸ Ãš Ã. But the saved file has no problem with  
> representation…

Alfonso, this isn’t a problem of Ruby, but a problem of the Windows  
console. To verify, open Notepad and enter your letters, then save the  
file. In the console, do a “type myfile.txt” (replace with the actual  
filename). You’ll see the same weird characters. The reason is that the  
Windows console uses a special character encoding.

If you want to convert the output of your Ruby programs to the character  
encoding of the Windows console, look at

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/225185](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/225185)

Regards,  
Pit

---

<div class="post-metadata">

**Author:** ![Alfonso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@Alfonso](https://www.ruby-forum.com/u/Alfonso)\
**Post date:** [November 17, 2006, 9:49am UTC](https://www.ruby-forum.com/t/encoding-in-windows-newby-question/76251/8 "2006-11-17T09:49:30Z")

</div>

Pit C. escribiÃ³:

> Alfonso, this isn’t a problem of Ruby, but a problem of the Windows  
> Regards,  
> Pit

That’s it. It works now, using iconv.

Thank you, Pit and Paul for your answers.

* * *

LLama Gratis a cualquier PC del Mundo.  
Llamadas a fijos y móviles desde 1 céntimo por minuto.  
[http://es.voice.yahoo.com](http://es.voice.yahoo.com)
