# String#downcase for accented letters in UTF-8?

**URL:** <https://www.ruby-forum.com/t/string-downcase-for-accented-letters-in-utf-8/57884>\
**Category:** Ruby\
**Created:** [April 15, 2006, 3:10pm UTC](https://www.ruby-forum.com/t/string-downcase-for-accented-letters-in-utf-8/57884 "2006-04-15T15:10:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gioele](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@gioele](https://www.ruby-forum.com/u/gioele)\
**Post date:** [April 15, 2006, 3:10pm UTC](https://www.ruby-forum.com/t/string-downcase-for-accented-letters-in-utf-8/57884/1 "2006-04-15T15:10:36Z")

</div>

How can I convert to lowercase a string that contains accented  
characters  
encoded in UTF-8?  
String#downcase does not work with accented letters.

---

<div class="post-metadata">

**Author:** ![gioele](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@gioele](https://www.ruby-forum.com/u/gioele)\
**Post date:** [April 15, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/string-downcase-for-accented-letters-in-utf-8/57884/2 "2006-04-15T17:10:19Z")

</div>

On Apr 15, 2006, at 15:08, Gioele B. wrote:

> How can I convert to lowercase a string that contains accented  
> characters  
> encoded in UTF-8?  
> String#downcase does not work with accented letters.

I hand-coded that:

# This library redefines String#tr so that it understands UTF-8.

require ‘jcode’

def normalize\_for\_sorting(s)  
return nil if s.nil?  
norm = s.downcase  
norm.tr!(‘ÁÉÍÓÚ’, ‘aeiou’)  
norm.tr!(‘ÀÈÌÒÙ’, ‘aeiou’)  
norm.tr!(‘ÄËÏÖÜ’, ‘aeiou’)  
norm.tr!(‘ÂÊÎÔÛ’, ‘aeiou’)  
norm.tr!(‘áéíóú’, ‘aeiou’)  
norm.tr!(‘àèìòù’, ‘aeiou’)  
norm.tr!(‘äëïöü’, ‘aeiou’)  
norm.tr!(‘âêîôû’, ‘aeiou’)  
norm  
end

– fxn
