Groovy: Replace / in path with \

How would you replace / with \ in Groovy? So "//10.1.1.1/temp/test" becomes "\\10.1.1.1\temp\test" .

"//10.1.1.1/temp/test".replaceAll(/'\\/'/,'\\') <-? does not work

Does anyone have any ideas?

Thanks for any answer.

+4
source share
2 answers

Look at this "//10.1.1.1/temp/test".replaceAll("/","\\\\") . "\\\\" does a backslash.

+9
source

Please check it

  String path = 'D:/folder1/folder2/yourfile' String result = path.replaceAll( "/","\\"); 

Finally, you get a result like

 'D:\folder1\folder2\yourfile' 
-1
source

All Articles