Groovy multiline string

I have a groovy line like this:

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

However, groovy is printed as "غ% ºW". How can I do this for printing exactly the same as in the line above. I do not want to hide \.

Thanks,

+4
source share
2 answers

Looks like what you want is a triple slashy string that doesn't exist (yet?)

You can 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 multi-line. 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

+4
source

How about this?

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

Any line enclosed in forward slashes (/) must not have a backslash ().

+1
source

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


All Articles