It's probably a carriage return, not a space -- then coerced to a space by HTML.
${name.substring(0,1).toUpperCase()}${name.substring(1).toLowerCase()}##
Whitespace is often (depending on context) preserved in Velo, which can lead to fun times.
Yup, that worked. Thanks again!
Hi Sanford Whiteman,
Thank you for sharing it. This is helpful and it worked. However, even after adding ## in the end of the code, the whitespace still appears. Can you help me please on how to remove the extra spaces?
Regards,
Ayush Aggarwal
If your code is exactly like the above, the whitespace isn't coming from Velocity.
Hi @SanfordWhiteman, can you clarify how to wrap in isEmpty() ? How should the final velocity script look combining the two scripts?
Script #1
#set($name = ${lead.FirstName})
$name.substring(0,1).toUpperCase()$name.substring(1).toLowerCase()
Script #2
#if( !$name.isEmpty() )
${name.substring(0,1).toUpperCase()}${name.substring(1).toLowerCase()}
#end
Could you highlight your code (as Java) please using the Syntax Highlighter here on the forum?
Correct combined scripts:
#set($name = ${lead.FirstName})
#if( !$name.isEmpty() )
${name.substring(0,1).toUpperCase()}${name.substring(1).toLowerCase()}
#end
One little thing. 🤓 You shouldn't use curly braces in directives (#set), only in output. (They happen to work in this simple case, but as code gets more complex they lead to syntax errors.)
#set( $name = $lead.FirstName )
#if( !$name.isEmpty() )
${name.substring(0,1).toUpperCase()}${name.substring(1).toLowerCase()}
#end