2016-07-05 10 views
0

Invalid list index 2は、index 2が定義されていないことを意味しています。 index 2がColdFusionで定義されているかどうかを確認するにはどうすればよいですか?無効なリストのインデックス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> 
+0

存在しない場合は空の文字列を返す 'getToken()'を使うことができます –

答えて

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

'ListLen( '/ pages.cfm/about-us /'、"/")gte 4'をあなたの最初のif節は、毎回チェックする必要はありません。 –

+3

また、 'ListLen( '/ pages.cfm/about-us /'、"/")neq '''は常にtrueを返します。 – Leigh

0

目標は、テキストが特定のパターンで始まり、すなわち「/ニュース/プレス/ 2016/{moreChars} /」、正規表現を使用する方が簡単だろう検証することである場合:

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