• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Initcap of a string

 
Gitanjali Magani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do i get the initcap of a string?

ex: convert "search again" to "Search Again"


thanks,
gita
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no trivial, built-in-to-the-API way to do it.

With a bit of care, you could do it all at once with a regular expression, or you could do it by looping over the characters in a String, appending them to a StringBuffer, capitalizing each letter than follows whitespace.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic