列表索引2无效

时间:2016-07-05 00:24:55

标签: coldfusion

我'我得到Invalid list index 2这意味着index 2中没有定义。如何检查ColdFusion中是否定义了index 2

<cfif
    ListGetAt('/pages.cfm/about-us/' 1 , "/") eq 'news' AND 
    ListGetAt('/pages.cfm/about-us/', 2 , "/") eq 'press' AND 
    ListGetAt('/pages.cfm/about-us/', 3 , "/") eq '2016'AND 
    ListGetAt('/pages.cfm/about-us/', 4 , "/") neq ''>
    <cfoutput>It Works!</cfoutput>
</cfif>

2 个答案:

答案 0 :(得分:0)

嘿,伙计们现在正在工作。

<cfif
    ListLen('/pages.cfm/about-us/', "/") neq '' AND
    ListGetAt('/pages.cfm/about-us/', 1 , "/") eq 'news' AND 
    ListLen('/pages.cfm/about-us/', "/") neq '' AND
    ListGetAt('/pages.cfm/about-us/', 2 , "/") eq 'press' AND 
    ListLen('/pages.cfm/about-us/', "/") neq '' AND
    ListGetAt('/pages.cfm/about-us/', 3 , "/") eq '2016'AND 
    ListLen('/pages.cfm/about-us/', "/") neq '' AND
    ListGetAt('/pages.cfm/about-us/', 4 , "/") neq ''>
    <cfoutput>It Works!</cfoutput>
</cfif> 

答案 1 :(得分:0)

如果目标是验证文本以特定模式开头,即&#34; / news / press / 2016 / {moreChars} /&#34;,则使用正则表达式会更简单:

<cfif REFindNoCase("^/news/press/2016/[^/]+/", theStringToSearch)>
    found
</cfif>