Groovy GDK equivalent of Apache Commons StringUtils.capitalize(str) or Perl's ucfirst(str)

Posted by knorv on Stack Overflow See other posts from Stack Overflow or by knorv
Published on 2009-03-25T14:24:59Z Indexed on 2011/01/15 6:53 UTC
Read the original article Hit count: 264

Filed under:
|
|
|

Yes/no-question: Is there a Groovy GDK function to capitalize the first character of a string?

I'm looking for a Groovy equivalent of Perl's ucfirst(..) or Apache Commons StringUtils.capitalize(str) (the latter capitalizes the first letter of all words in the input string).

I'm currently coding this by hand using ..

str = str[0].toUpperCase() + str[1 .. str.size() - 1]

.. which works, but I assume there is a more Groovy way to do it. I'd imagine ucfirst(..) being a more common operation than say center(..) which is a standard method in the Groovy GDK (see http://groovy.codehaus.org/groovy-jdk/java/lang/String.html).

© Stack Overflow or respective owner

Related posts about string-manipulation

Related posts about grails