17

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?

zorza
  • 2,814
  • 3
  • 27
  • 41
  • Same approach (possibly trough intermediate variable(s)): get first letter of your `FooBarTest` and make it lower case; now concatenate it with other letters in that string (unless, of course, there is Java method that can upper case only first letter in a string). – LazyOne Nov 10 '15 at 09:07
  • 2
    Since I'm not a velocity expert by any means .. I may offer only this ugly code: 1) `#set($first_letter = $controller.substring(0,1).toLowerCase())` 2) `#set($the_rest = $controller.substring(1))` 3) `class Controller_${first_letter}${the_rest}`. You should be able to reduce the number of lines to 2 or even 1... – LazyOne Nov 10 '15 at 09:10

1 Answers1

38

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.

nanocv
  • 2,227
  • 2
  • 14
  • 27
zorza
  • 2,814
  • 3
  • 27
  • 41