Checking if a string contains a particular substring in Velocity

In Velocity I have a variable called $url which contains the following string: [ContentId(2.7507), ContentId(2.7508), ContentId(1.44551)]

I want to check if that string contains the substring 1.44551.

This is the code I've written so far, but for some reason it's returning 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

I would expect this to be returning True, as the 1.44551 substring is present in the $url variable. Please can someone tell me where I'm going wrong?


Velocity holds Objects values in context map. Just add toString to make sure you execute on String the contains method:

 #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
链接地址: http://www.djcxy.com/p/65736.html

上一篇: removeWithCompletionHandler错误

下一篇: 检查一个字符串是否包含Velocity中的特定子字符串