Forum: Ruby on Rails upcase special chars (åäöü...)?

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.
6738e5c4f17822f7e163ba938344755d?d=identicon&s=25 Daniel (Guest)
on 2006-04-18 23:32
Hey guys

How do you upcase the special characters (åäöü)?
I use latin-1 and not utf-8.


How did you solve this problem? (nice ruby way or ugly hack doesnt
matter)

Daniel
6738e5c4f17822f7e163ba938344755d?d=identicon&s=25 Daniel (Guest)
on 2006-04-19 13:33
Ok, this is what I have come up with so far... pretty ugly, but it
works.

def myupcase(stringtoupper)
 stringtoupper.upcase.gsub('å','�').gsub('ä','�').gsub('ö','�').gsub('ü','�').gsub('ñ','�').gsub('ï','Ï')
end


//Daniel
Ec5a599777854c540fd102ef4691fe10?d=identicon&s=25 Rimantas Liubertas (Guest)
on 2006-04-19 13:43
(Received via mailing list)
> Ok, this is what I have come up with so far... pretty ugly, but it
> works.
>
> def myupcase(stringtoupper)
>stringtoupper.upcase.gsub('å','Å').gsub('ä','Ä').gsub('ö','Ö').gsub('ü','Ü').gsub('ñ','Ñ').gsub('ï','Ï')
> end

How about:

stringtoupper.upcase.tr('åäöüñï','ÅÄÖÜÑÏ')


Regards,
Rimantas
--
http://rimantas.com/
13ea48f056b19349027d2f4a6921a46a?d=identicon&s=25 Jean-François (Guest)
on 2006-04-19 13:43
(Received via mailing list)
Hello,

> Ok, this is what I have come up with so far... pretty ugly, but it
> works.
>
> def myupcase(stringtoupper)
> 
stringtoupper.upcase.gsub('å','�').gsub('ä','�').gsub('ö','�').gsub('ü','�').gsub('ñ','�').gsub('ï','Ï')
> end

In this case, you can use String#tr :

stringtoupper.upcase.tr('åäöüñï', '�����Ï')

     -- Jean-François.
Bef7ff8a0537495a1876ffebdc9f8e51?d=identicon&s=25 Lionel Bouton (Guest)
on 2006-04-19 14:05
(Received via mailing list)
Daniel wrote the following on 19.04.2006 13:33 :

>
>

If you don't need the old upcase behaviour, you can put the following
where needed (probably in lib/string_overload.rb and 'require'd in
application.rb and/or application_helper.rb):

class String
    alias_method :old_upcase, :upcase
    def upcase
       self.old_upcase.tr('åäöüñï', '�����Ï')
    end
end
This topic is locked and can not be replied to.