Groovy: How can I include backslashes inside a string without escaping?

后端 未结 1 1970
逝去的感伤
逝去的感伤 2021-02-05 07:11

I want to use the following string literal inside my groovy program without having to escape the backslashes:

C:\\dev\\username

Here is what I have t

1条回答
  •  遥遥无期
    2021-02-05 07:24

    Wow, another gotcha with putting Windows files paths in slashy strings. Nice catch. The gotcha I've encountered before was including a trailing backslash on the path, e.g. /C:\path\/, which results in an unexpected char: 0xFFFF error.

    Anyways, for the sake of an answer, given that Windows paths are case insensitive, why not exploit it for once?

    def s = /C:\DEV\USERNAME/
    

    The \u unicode character escape sequence is case sensitive.

    0 讨论(0)
提交回复
热议问题