title: Ruby and Accented Characters
body: <p>Summary of the wall of text below: How can I display accented characters (so they work via puts, etc) in Ruby?</p>
  
  <hr>
  
  <p>Hello! I am writing a program for my class which will display some sentences in Spanish. When I try to use accented characters in Ruby, they do not display correctly (in the NetBeans output window (which displays accented characters in Java fine) or in the Command Prompt).</p>
  
  <p>At first, some of my code didn't even run because the accented characters in my arrays where throwing off the Ruby interrupter (I guess?). I got errors like Ruby was expecting a closing bracket.</p>
  
  <p>But I did some research, and found a solution, to add the following line of code to the beginning of my Ruby file:</p>
  
  <p><code># coding: utf-8</code></p>
  
  <p>In NetBeans, my program ran regardless of this line. But I needed to add this line to get my program to run successfully in Command Prompt. (I don't know why.)</p>
  
  <p>I'm still, however, having a problem actually displaying the characters to the screen. A word such as "será" will display in the NetBeans output window as "serÃ©". And in the command prompt it draws little pipe characters (that I don't know how to type).</p>
  
  <p>Doing some more research, I heard about:</p>
  
  <p><code>$KCODE = 'UTF-8'</code></p>
  
  <p>but I'm not having any luck with this.</p>
  
  <hr>
  
  <p>I'm using Ruby 1.8 and 1.9 (I go back and forth between different machines).</p>
  
  <p>Thanks,
  Derek</p>