groovy multiline string escape all

时间:2011-02-14 23:33:56

标签: groovy

我有一个像这样的groovy字符串:

String test = 

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

然而,groovy打印出来像“غ%ºW”。如何使其打印出来与上面的字符串完全相同。我不想逃避\。

谢谢,

2 个答案:

答案 0 :(得分:4)

听起来你想要的是那个不存在的tripple slashy字符串(还没有?)

您可以尝试:

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

更新!现在在Groovy 1.8中,slashy字符串是多行的。这应该有效:

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

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

答案 1 :(得分:1)

这个怎么样?

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

由正斜杠(/)括起的任何字符串都不需要对反斜杠()进行转义。

相关问题