逃避在groovy [英] Escaping in groovy
本文介绍了逃避在groovy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个帮助,在groovy中转义
I need a help in escaping in groovy
我在文本文件中有一些字符串,如这样#$ commonTomcat620.max_threads $#这些值我必须在runTime中替换。
I have some string in text file like this #$commonTomcat620.max_threads$# These value i have to replace in runTime.
我使用以下代码:
def str = "#\$commonTomcat620.max_threads\$#"
fileContents = fileContents.replaceAll("${str}","100");
这个str是以#$ commonTomcat620.max_threads $#的形式打印出来的。但不能替换文件。我尝试用$#。这是工作。
This str is printin the values as #$commonTomcat620.max_threads$#. but not replacing in file. I tried withOut #$ . it is working.
谢谢。
推荐答案
你有几个选项可以逃脱美元符号:
You have a couple of options to escape the dollar sign:
这个工作(用美元斜线的字符串):
This works (with dollar-slashy strings):
def str = $/#\$$commonTomcat620.max_threads\$$#/$
或者(带单引号字符串):
Or this (with single quote strings):
def str = '#\\$commonTomcat620.max_threads\\$#'
其他选项也可能存在
这篇关于逃避在groovy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文