Sean Nguyen
Sean Nguyen

Reputation: 13128

groovy multiline string escape all

I have a groovy string like this:

String test = 

"""     
abc{ der}
token: "\330\272%\006\272W\264\000T\226\022[\310\2207#fs\032q"      
""";

However groovy is printing out like "غ%ºW". How can I make it to print out exactly like the above string. I don't want to escape the \.

Thanks,

Upvotes: 4

Views: 4611

Answers (3)

Mark Rouge
Mark Rouge

Reputation: 1

This would work, testing in Groovy 2.4.xx

def testMultiLine = $/
test
test1
test2
/$

Upvotes: 0

Andrew
Andrew

Reputation: 4624

It sounds like what you want is the tripple slashy string, which doesn't exist (yet?)

You might try:

String token = /\330\272%\006\272W\264\000T\226\022[\310\2207#fs\032q/
String test = """
abc{ der}
token: "${token}"
"""

Update! Now in Groovy 1.8, the slashy string is multiline. This should work:

String test = /
abc{ der}
token: "\330\272%\006\272W\264\000T\226\022[\310\2207#fs\032q"
/

See: http://docs.codehaus.org/display/GROOVY/Groovy+1.8+release+notes#Groovy1.8releasenotes-Slashystrings

Upvotes: 4

Dónal
Dónal

Reputation: 187529

How about this?

String test = """
abc{ der}
token: "${/\330\272%\006\272W\264\000T\226\022[\310\2207#fs\032q/}"
"""

Any String that is enclosed by forward-slashes (/) does not need to have the backslashes () escaped.

Upvotes: 1

Related Questions