检查字符串是否包含速度中的特定子字符串



在速度i中有一个称为$ url的变量,其中包含以下字符串:[contentId(2.7507),contentid(2.7508),contentid(1.44551)]

>

我想检查该字符串是否包含子字符串1.44551。

这是我到目前为止写的代码,但是由于某种原因,它正在返回false:

#if($url.contains("1.44551"))
<p>The article content id is 1.44551</p>
#else
<p>The article content id isn't 1.44551</p>
#end

我希望这将是正确的,因为$ URL变量中存在1.44551子字符串。请有人告诉我我要去哪里?

速度在上下文映射中以对象保存值。

如果要执行字符串方法,请添加toString以确保在字符串上执行contains方法:

 #if($url.toString().contains("1.44551"))
<p>The article content id is 1.44551</p>
#else
<p>The article content id isn't 1.44551</p>
#end

最新更新