Lowercase first letter in Apache Velocity

zorza picture zorza · Nov 9, 2015 · Viewed 7.4k times · Source

I've got this code, which converts "dotted" string to camelCase in WebStorm File Template:

#set($Controller_name = ${StringUtils.removeAndHump(${NAME}, ".")})

For example it converts foo.bar.test to FooBarTest.

But what I need is to convert it from foo.bar.test to fooBarTest.

How can I do that?

Answer

zorza picture zorza · Nov 15, 2015

This is what finally worked for me:

#set($Controller_name = ${StringUtils.removeAndHump(${NAME}, ".")})
#set($first_letter = $Controller_name.substring(0,1).toLowerCase())
#set($the_rest = $Controller_name.substring(1))
#set($Controller_name = ${first_letter} + ${the_rest})

It could be shortened to:

#set($Controller_name = ${StringUtils.removeAndHump(${NAME}, ".")})
#set($Controller_name = $Controller_name.substring(0,1).toLowerCase() + $Controller_name.substring(1))

Thanks @LazyOne for pointing me in the right direction.