Velocity script function to output text as Title Caps
Does a function exist for Velocity that will transform a string of text to title caps format? For example, if first name is in all-caps, how can output that as Xxxxx?
Does a function exist for Velocity that will transform a string of text to title caps format? For example, if first name is in all-caps, how can output that as Xxxxx?
Hi @dan_stevens_ ,
Unfortunately, there isn't a built-in method in velocity for capitalizing each word in a string. So we manually achieve title casing by splitting the input text into words, capitalizing the first letter of each word, and converting the rest of the letters to lowercase.
In this example, the input text "take me out to the ballgame" will be converted to "Take Me Out To The Ballgame" using Velocity script.
#set($inputText = "take me out to the ballgame")
#set($words = $inputText.split(" "))
#foreach($word in $words)
#set($capitalizedWord = $word.substring(0,1).toUpperCase() + $word.substring(1).toLowerCase())
$capitalizedWord##
#end
Ending the output with a ## to remove any extra spaces
$capitalizedWord##
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.