[英]How do I Escape a Double Quote in Velocity 2.0?
I'm using Velocity 2.0. 我正在使用Velocity 2.0。 I've created a method in a custom tool that finds and returns a substring between two strings.
我已经在自定义工具中创建了一个方法,该方法可以找到并返回两个字符串之间的子字符串。 This method takes three arguments: the initial string, a beginning subsequence, and an ending subsequence.
此方法采用三个参数:初始字符串,开始子序列和结束子序列。 I've verified that this is working with unit tests.
我已验证这可用于单元测试。
My question is this: how do, in my velocity template, escape quotes so that I can pass in a string that contains double quotes? 我的问题是这样的:如何在我的速度模板中转义引号,以便我可以传递包含双引号的字符串?
My initial string $mystr
is a json snippet and will look something like: 我的初始字符串
$mystr
是一个json代码段,看起来像这样:
"receiver":"867-5309",
I'm trying to extract the 867-5309
from the string, which means that my begin string is "receiver":"
and my end string is ",
我正在尝试从字符串中提取
867-5309
,这意味着我的开始字符串是"receiver":"
而我的结束字符串是",
I've tried: 我试过了:
$stringTool.findSubstringBetween($mystr, """receiver"":"", """,")
and 和
$stringTool.findSubstringBetween($mystr, "\"receiver\":\", "\",")
but neither of these works (the first one causes a ParseErrorException, and the second yields double backslashes in the values passed to the method). 但是这些都不起作用(第一个引发ParseErrorException,第二个传递给方法的值产生双反斜杠)。
You can try setting this 您可以尝试设置
#set ( $d = '"')
Then you can use 那你可以用
${d}
In place of the quotation in the strings. 代替字符串中的引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.