# How to capitalize UTF8 string without downcasing

**URL:** <https://www.ruby-forum.com/t/how-to-capitalize-utf8-string-without-downcasing/132475>\
**Category:** Rails I18n\
**Created:** [March 20, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/how-to-capitalize-utf8-string-without-downcasing/132475 "2008-03-20T15:15:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![janfoeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8baadc/32.png) [@janfoeh](https://www.ruby-forum.com/u/janfoeh)\
**Post date:** [March 20, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/how-to-capitalize-utf8-string-without-downcasing/132475/1 "2008-03-20T15:15:46Z")

</div>

What is the best way to capitalize the first character of a UTF8 string?

String#capitalize downcases the rest of the string which is unacceptable  
since there can be capitals in the middle of the string. (“see New  
York”.capitalize =\> “See new york”). Just picking off the first byte and  
capitalizing that is also not an option since the first character can be  
a multibyte UTF-8 character.

The only thing I can think of so far is either using Ruby 1.9 or the the  
Rails multibyte Chars library to split off the first character and then  
capitalize that and join it back together.

Surely there must be a better way for such a common problem?

---

<div class="post-metadata">

**Author:** ![janfoeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8baadc/32.png) [@janfoeh](https://www.ruby-forum.com/u/janfoeh)\
**Post date:** [August 12, 2008, 11:23pm UTC](https://www.ruby-forum.com/t/how-to-capitalize-utf8-string-without-downcasing/132475/2 "2008-08-12T23:23:25Z")

</div>

I am having the same problem. What’s the best solution sans-migrating  
to a new version of Ruby?

---

<div class="post-metadata">

**Author:** ![janfoeh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8baadc/32.png) [@janfoeh](https://www.ruby-forum.com/u/janfoeh)\
**Post date:** [August 12, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/how-to-capitalize-utf8-string-without-downcasing/132475/3 "2008-08-12T23:34:39Z")

</div>

I ended up doing it like this:

Class ::String  
def firstcap  
self.gsub(/^(\w)/) { $1.chars.capitalize } # /^([a-z])/  
end  
end
