我有一个时髦的字符串是这样的:常规多串逃避所有
String test =
"""
abc{ der}
token: "\330\272%\006\272W\264\000T\226\022[\310\2207#fs\032q"
""";
但是Groovy是打印出像 “غ%ºW”。我怎样才能打印出完全像上面的字符串。我不想逃避\ \。
感谢,
我有一个时髦的字符串是这样的:常规多串逃避所有
String test =
"""
abc{ der}
token: "\330\272%\006\272W\264\000T\226\022[\310\2207#fs\032q"
""";
但是Groovy是打印出像 “غ%ºW”。我怎样才能打印出完全像上面的字符串。我不想逃避\ \。
感谢,
这听起来像你想要什么特里普尔slashy字符串,它不存在
你可以尝试(没有?):
String token = /\330\272%\006\272W\264\000T\226\022[\310\2207#fs\032q/
String test = """
abc{ der}
token: "${token}"
"""
更新!现在在Groovy 1.8中,斜杠字符串是多行的。这应该工作:
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
这个怎么样?
String test = """
abc{ der}
token: "${/\330\272%\006\272W\264\000T\226\022[\310\2207#fs\032q/}"
"""
任何由正斜杠(/)括起来的字符串不需要反斜杠()。
我真的不想修改“”“”“”“中的任何内容。我曾经从java中的一个文件中读取它,我希望能从我的groovy代码中直接声明它。 – 2011-02-15 17:32:04