DEV Community

ouryperd
ouryperd

Posted on

My own capitalizeFully() in Groovy

I used to use org.apache.commons.lang3.text.WordUtils.capitalizeFully() but I have been having problems. I made my own method in Groovy.

def capitalizeFully(String str, String delim=" ") { //optional delimiter
    def li = []
    str.split(delim).each { word ->
        li.add(word.capitalize())
    }
    return li.join(delim)
}
Enter fullscreen mode Exit fullscreen mode

assert capitalizeFully("A silly string with words") == "A Silly String With Words"

Top comments (0)