Backslash at live template groovy script

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?

4 comments
Comment actions Permalink

You can use .replaceAll("/", "\\\\"); for that.

0
Comment actions Permalink

With:

groovyScript("String p=_editor.getVirtualFile().getPath().replaceAll("/", "\\\\");")  

error:

startup failed:
Script1.groovy: 1: Unexpected input: '(' @ line 1, column 55.
ualFile().getPath().replaceAll(
^

1 error
0
Comment actions Permalink

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('/', '\\\\');")

1
Comment actions Permalink

Yes, now it works. Thanks

0

Please sign in to leave a comment.