In groovy, how to assign a multi-line string WITHOUT ESCAPING slash (\) and without interpolation

in groovy, what if I want a multiline string without interpolation and WITHOUT OFF

sort of:

var1="hello hello" var2="""/ adakldjkadj\^mk as@da \kl#DFD#$# ${var1} d3&657\7fdsfsf /""" println var2; 

should print in the same way as he does, for example:

adakldjkadj \ ^ tk
a @ yes \ cl # DFD # $ #
$ {Var1}
d3 & 657 \ 7fdsfsf

THIS, $ {var1} was NOT extended, and escaping \ was not necessary, and this is a multi-line string
THEN HOW TO APPOINT THIS HEREDOC IN GROOVY SERIES. This is possible in a bash script, ruby, perl, etc.

expressed in ruby ​​as (pay attention to the quotation marks around separating characters, such as: "EOL")

 a = <<'EOL' adakldjkadj\^mk as@da \kl#DFD#$# yes ${var1} d3&657\7fdsfsf EOL 

How to do it in groovy?

+4
source share
3 answers

Use triple single quotes, such as ''' instead of double quotes, to avoid interpolating variables in multi-line strings.

+2
source

This is not possible, see here: https://issues.apache.org/jira/browse/GROOVY-411

+1
source

You can get closer, but still not what you are looking for using single quotes. It will no longer extend $ {var1}.

Regarding the \ character, which is always a java / groovy delimiter for special characters, so you should always avoid it.

Edit: It looks like they are working on this for 1.8 or already in 1.8. I am currently using only 1.7, so I cannot verify or provide sample code.

+1
source

Source: https://habr.com/ru/post/1343759/


All Articles