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
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
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
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(‘åäöüñï’,‘ÅÄÖÜÑÏ’)
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.
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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs