Forum: Ruby on Rails cleaning a string and encoding problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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)
hi,
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
   str.delete!(".,:(){}!|\"\\")

   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]
     end
   end

   str
end

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.