RemoveChars函数的2参数(现在为0)必须是正整数

时间:2015-09-09 18:10:41

标签: coldfusion coldfusion-9

浏览zzvp.cfm页面时出现此错误

The 2 parameter of the RemoveChars function, which is now 0, must be a positive integer


The error occurred in /www/zzvp.cfm: line 578
 Called from /www/zzvp.cfm: line 530
 Called from /www/zzvp.cfm: line 1
 576 :              <cfset updir = #RemoveChars(updir, len(updir), 1)#>
 577 :              <cfloop condition = "Right(updir, 1) neq '\'">
 578 :                  <cfset updir = #RemoveChars(updir, len(updir), 1)#>
 579 :              </cfloop>
 580 :              <th class=chkbx><input type=checkbox width='13px'
   class=chkbx></th><td width="20%"><strong><a href="?action=goto&scr=#updir#">..</a></strong></td>`

有关如何解决此问题的任何想法?

1 个答案:

答案 0 :(得分:0)

即使我没有得到代码背后的逻辑,下面描述了您的问题。

错误即将发生,因为字符串长度变为零,但仍未找到\。添加一个额外的条件来检查循环中字符串的长度。

<cfloop condition = "Right(updir, 1) neq '\' AND  len(updir)">
    <cfset updir = RemoveChars(updir, len(updir), 1)>
</cfloop>

对于这种逻辑,我认为有更好的方法可以在没有循环的情况下实现这种逻辑。请参阅以下内容。

<!--- Treat string as a list with \ as delimiter ---> 
<cfset updir = ListDeleteAt(updir, listlen(updir,'\'), '\') >

<!--- Reverse string --->
<cfset updir = Reverse(updir)> 
<!--- Get from left till the position of the \  --->
<cfset updir = Left( Reverse(updir), len(updir) - find(updir , '\') + 1 ) >