ASP经典 - 我该如何加入一个字符串数组/加盟/破灭不工作 [英] ASP classic - how do I join an array of strings / join / implode do not work

查看:161
本文介绍了ASP经典 - 我该如何加入一个字符串数组/加盟/破灭不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 暗淡stringIdCollection
    stringIdCollection =加入(的Request.Form(ID),,))
昏暗whereStatement
    whereStatement =WHERE ID IN('&放大器; stringIdCollection&安培;');

我得到这个错误:


  

微软VBScript编译错误800a0401


  
  

语句结束的预期。


  
  

/includes/Process.asp,行49 stringIdCollection =加入(
  的Request.Form(ID),,))
  -------------------------------------------------- ---------------------- ^


它甚至有可能使用加入上的Request.Form?

我想输出是:


  

WHERE ID IN('122','344','599')



解决方案

加入函数需要一个数组作为第一个参数。在经典ASP(VBScript)的数据的Request.Form 总是字符串,所以不可能有一个实际的数组,你必须建立自己的数组:

  myarray的暗淡
myArray的=阵列(的Request.Form(ID)的Request.Form(ID2)的Request.Form(ID3))昏暗stringIdCollection
stringIdCollection =加入(myarray的,,))

另请注意,在传统的ASP,如果您提交多个表单域具有相同的名称(即 ID ),他们将获得请求。表格已经由一个逗号分隔。

相反的是可以用PHP来完成,命名多个表单域用方括号[]在末尾追加,ASP将无法将其转换为的Request.Form数组。

Dim stringIdCollection
    stringIdCollection = Join( Request.Form( "id" ), "', '" ) )    
Dim whereStatement
    whereStatement = "WHERE id IN ('" & stringIdCollection & "');"

I get this error:

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/includes/Process.asp, line 49 stringIdCollection = Join( Request.Form( "id" ), "', '" ) ) ------------------------------------------------------------------------^

Is it even possible to use Join on a Request.Form?

I would like the output to be:

"WHERE id IN ('122', '344', '599')"

解决方案

The join function expects an array as the first parameter. In Classic ASP (VBScript) the data in Request.Form is always string, so impossible to have an actual array in it, you have to build the array yourself :

Dim myArray
myArray = Array(Request.Form("id"), Request.Form("id2"), Request.Form("id3"))

Dim stringIdCollection
stringIdCollection = Join( myArray , "', '" ) ) 

Also notice that in Classic ASP, if you submit multiple form fields with the same names (i.e. id), they will get in Request.Form already separated by a commas.

Contrary to what can be done in PHP, naming multiple form fields with square brackets [] appended at the end, ASP will not convert it as an array in Request.Form.

这篇关于ASP经典 - 我该如何加入一个字符串数组/加盟/破灭不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆