Backslash at live template groovy script Follow
I want change all slash to backslash at path for live template variable with groovy script, where bashslash is escape special character.
When I use :
groovyScript("String p=_editor.getVirtualFile().getPath().replaceAll('/', '\');")
slash change for empty.
When I use:
groovyScript("String p=_editor.getVirtualFile().getPath().replaceAll('/', '\\');")
I have error:
startup failed:
Script1.groovy: 1: Unexpected character: '\'' @ line 1, column 61.
e().getPath().replaceAll('/', '\');
^
1 error
How properly change slash / to backslash \ at path?
Please sign in to leave a comment.
You can use
.replaceAll("/", "\\\\");
for that.With:
error:
Sorry, I should have checked that in an actual live template instead of just a Groovy script.
Please try this one instead:
groovyScript("return _editor.getVirtualFile().getPath().replace('/', '\\\\');")
Yes, now it works. Thanks