[英]How to convert a string to camel case in phpstorms (velocity based) file tempates?
What I've tried so far is: 到目前为止我尝试过的是:
## $NAME is something like 'my_controller_c'
#set($NAME = $NAME.removeAndHump($NAME))
#set($NAME = $NAME.underscoresToCamelCase(String)
But that does not work. 但这不起作用。 The first one does nothing, the second one throws an java error.
第一个没有做任何事情,第二个抛出java错误。
I also tried using regular expressions and to loop through the string, but my java knowledge is very basic. 我也尝试使用正则表达式并循环遍历字符串,但我的java知识是非常基本的。
The following works in PhpStorm 9 (and probably all of the other JetBrains IDEs, I would guess): 以下适用于PhpStorm 9(可能还有所有其他JetBrains IDE,我猜):
#set($new_name = ${StringUtils.removeAndHump(${NAME}, "-")})
class $new_name {
}
This is, what I ended up doing: 这就是我最终做的事情:
#set($ctrlName = $NAME.replaceAll("-c$", ""))
#set($ctrlNewName = "")
#foreach($str in $ctrlName.split("-"))
#set($str = $str.substring(0,1).toUpperCase()+$str.substring(1))
#set($ctrlNewName = $ctrlNewName + $str)
#end
#set ( $ctrlNewName = $ctrlNewName + "Ctrl" )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.