我有一个字符串creationDate = "add_months(sysdate,-1)"
。我必须删除双引号,以便我可以在数据库查询中使用该值。我试过了replace
和replaceAll
但我没有运气。我的代码是groovy
答案 0 :(得分:0)
如果输入字符串是"add_months(sysdate,-1)"
并且那些双引号确实在字符串中,那么您可以通过多种方式删除双引号。一个是使用下标运算符内部的范围,如下所示:
groovy:000> input = '"add_months(sysdate,-1)"'
===> "add_months(sysdate,-1)"
groovy:000>
groovy:000> input
===> "add_months(sysdate,-1)"
groovy:000>
groovy:000> result = input[1..-2]
===> add_months(sysdate,-1)
groovy:000>
groovy:000> input
===> "add_months(sysdate,-1)"
groovy:000>
groovy:000> result
===> add_months(sysdate,-1)
请注意,input[1..-2]
计算为以第二个字符开头并以第二个字符结尾的字符串。
我希望有所帮助。