Forum: Ruby on Rails cleaning a string and encoding problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Borja =?iso-8859-1?Q?Mart=EDn?= (Guest)
on 2006-01-06 22:43
(Received via mailing list)
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 topic is locked and can not be replied to.