[英]How to replace string in Groovy
I have some string like我有一些像
C:\dev\deploy_test.log
I want by means of Groovy to convert string to我想通过 Groovy 将字符串转换为
C:/dev/deploy_test.log
I try to perform it with command我尝试用命令执行它
Change_1 = Log_file_1.replaceAll('\','/');
It doesn't convert this string它不转换这个字符串
您需要转义反斜杠\\
:
println yourString.replace("\\", "/")
You could also use Groovy's slashy string , which helps reduce the clutter of Java's escape character \
requirements.您还可以使用 Groovy 的slashy string ,这有助于减少 Java 转义字符\
要求的混乱。 In this case, you would use:在这种情况下,您将使用:
Change_1 = Log_file_1.replaceAll(/\/,'/');
Slashy strings also support interpolation, and can be multi-line. Slashy 字符串也支持插值,并且可以是多行的。 They're a great tool to add to your expertise.它们是增加您的专业知识的好工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.