Cleaning a string and encoding problem

I have the following script to clean a string sent through a form:

def clean_up(string)
chars = {
“á” => “a”,
“é” => “e”,
“í” => “i”,
“ó” => “o”,
“ú” => “u”,
“ñ” => “n”,
" " => “-”

str = string.dup

for i in 0…str.length - 1 do
char = str[i,1]
logger.debug(“log: #{char}”)
if chars.has_key?(char)
str[i,1] = chars[char]


the problem is that I have to encode this file in
ascii mode and use the iso-8859-1 headers if I
want it to work because otherwise the chars will
not be recognized in the hash key set(something
logic). so the question is, is there anyway to
achieve this but having this file encoded in
utf-8 like the others and having the headers in utf-8, too?

thanks in advance

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs