user658098
user658098

Reputation: 61

in groovy, how to assign multiline string WITHOUT ESCAPING slash(\) and without interpolation

in groovy , what to do if i want multiline string without interpolation and WITHOUT ESCAPING

something like:

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

println var2;

should print exactly the same as it is, like:

adakldjkadj\^mk
as@da\kl#DFD#$#
${var1}
d3&657\7fdsfsf

THAT IS, THE ${var1} has NOT been expanded, AND the escaping the \ was not needed and it is multiline string
THEN HOW TO ASSIGN THIS HEREDOC STRING IN GROOVY. This is possible in bash script, ruby,perl etc.

in ruby it is expressed as (notice the quotes around the delimiter chars like: 'EOL')

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

how to do it in groovy?

Upvotes: 5

Views: 8616

Answers (3)

Mikezx6r
Mikezx6r

Reputation: 16905

You can get closer, but still not what you're looking for, using single-quotes. It won't expand the ${var1} anymore.

As far as the \, that's always a java/groovy delimiter for special characters, so you'll always have to escape it.

Edit: Looks like they're working on this for 1.8, or it's already in 1.8. I'm currently only running 1.7, so can't test or provide a code example.

Upvotes: 1

Chii
Chii

Reputation: 14738

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

Upvotes: 1

sschuberth
sschuberth

Reputation: 29811

Use triple single quotes like ''' instead of double quotes to avoid variable interpolation in multi-line strings.

Upvotes: 4

Related Questions