ASP 经典 - 如何加入字符串数组/加入/内爆不起作用

Jim*_*988 3 join request.form asp-classic

Dim stringIdCollection
    stringIdCollection = Join( Request.Form( "id" ), "', '" ) )    
Dim whereStatement
    whereStatement = "WHERE id IN ('" & stringIdCollection & "');"
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Microsoft VBScript 编译错误“800a0401”

预计声明结束

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

是否可以在 Request.Form 上使用 Join ?

我希望输出是:

“哪里 ID 在('122','344','599')”

Max*_*eat 6

join函数需要一个数组作为第一个参数。在经典 ASP (VBScript) 中,数据Request.Form始终是字符串,因此其中不可能有实际的数组,您必须自己构建数组:

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

Dim stringIdCollection
stringIdCollection = Join( myArray , "', '" ) ) 
Run Code Online (Sandbox Code Playgroud)

另请注意,在经典 ASP 中,如果您提交多个具有相同名称(即id)的表单字段,它们将Request.Form已以逗号分隔。

与 PHP 中可以做的相反,在末尾附加方括号 [] 命名多个表单字段,ASP 不会将其转换为 Request.Form 中的数组。