Booyeoo
Booyeoo

Reputation: 583

Groovy: Replace / in Path with \

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

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

Does anyone have an idea?

Thanks for any answer.

Upvotes: 4

Views: 12304

Answers (2)

Mohammed Shaheen MK
Mohammed Shaheen MK

Reputation: 1219

Please check this

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

Finally you get result like

'D:\folder1\folder2\yourfile' 

Upvotes: -1

emstol
emstol

Reputation: 6206

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

Upvotes: 12

Related Questions