Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace string in Groovy

Tags:

groovy

I have some string like

C:\dev\deploy_test.log 

I want by means of Groovy to convert string to

C:/dev/deploy_test.log 

I try to perform it with command

Change_1 = Log_file_1.replaceAll('\','/'); 

It doesn't convert this string

like image 945
Bilow Yuriy Avatar asked Oct 03 '16 11:10

Bilow Yuriy


People also ask

What should I replace groovy with?

Java, Scala, Kotlin, Python, and Gradle are the most popular alternatives and competitors to Groovy.

How do I remove a string in Groovy?

Groovy has added the minus() method to the String class. And because the minus() method is used by the - operator we can remove parts of a String with this operator. The argument can be a String or a regular expression Pattern. The first occurrence of the String or Pattern is then removed from the original String.


1 Answers

You need to escape the backslash \:

println yourString.replace("\\", "/") 
like image 110
baao Avatar answered Oct 04 '22 15:10

baao