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,
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
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.
This would work, testing in Groovy 2.4.xx
def testMultiLine = $/
test
test1
test2
/$
精彩评论