来自经典ASP中Request

来自经典ASP中Request

本文介绍了来自经典ASP中Request.Form的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,在那些答复者的帮助下,我意识到我的问题是有关Request.Form Data是否为字符串的,就像a$="FooBar"是字符串和Array在Classic中的命令一样ASP.

I now realise after the help from those who replied that my question was about whether Request.Form Data is a string in the same way that a$="FooBar" is a string and the Array command in Classic ASP.

我正在尝试根据在表单中提交的数据制作一个数组.

I'm trying to make an Array from data submitted in a Form.

表单字段是动态创建的,并且具有相同的名称"subj".

The form fields are dynamically created and have the same name "subj".

Response.Write(Request.Form("subj"))产生:

"Welcome and Introduction, Talk1, Talk2 ,Interactive review of the conference"

当我检查TypeNameVarType Request.Form("subj")是一个字符串时.然后我编码:

When I check the TypeName or VarType Request.Form("subj") is a string. Then I code:

subjs = """" & Replace(Request.Form("subj"), ", ", """,""") & """"
subjects = Array(subjs)

有意给予:

subjs = "Welcome and Introduction","Talk1","Talk2","Interactive review of the conference"

subjects(0) = Welcome and Introduction

subject(1) = Talk1

subject(2) = Talk2

subject(3) = Interactive review of the conference

问题是我实际上得到的是:

The problem is that what I actually get is:

subjs = "Welcome and Introduction","Talk1","Talk2","Interactive review of the conference"

subject(0) = "Welcome and Introduction","Talk1","Talk2","Interactive review of the conference"

由于某种原因,由于没有主题(1),主题(2)或主题(3),所以数组的格式不正确.

For some reason the Array isn't correctly formed as there is no subject(1) subject(2) or subject(3).

如果我将subjs的输出实际复制并粘贴到我的代码中,则Array可以正常工作,但是我无法使Array在Form Data上工作.

If I physically copy and paste the output of subjs into my code, then Array works fine but I can't get the Array to work on Form Data.

我尝试使用CStr并检查了所有引号.

I've tried using CStr and checked all of the quotation marks.

为什么不起作用?

感谢那些麻烦回答的人.虽然Split确实可以在没有逗号的字段中工作,但按照@ Kul-Tigin的说法,SET var = Request.Form("subj")却是关键,但我希望能听到其他想法

Thank you to those who took the trouble to reply. Whilst Split does work in fields without commas, SET var = Request.Form("subj") as per @Kul-Tigin, I think is the key but would be keen to hear other thoughts

推荐答案

由于请求集合值可能包含逗号,因此使用split可能会导致意外结果.

Since the request collection values may contain commas, using split can cause unespected results.

通过集合创建数组更加可靠.

Creating an array through the collection is more reliable.

Set subject = Request.Form("subj")

ReDim subjects(subject.Count - 1)

For i = 1 To subject.Count
    subjects(i - 1) = subject(i)
Next

这篇关于来自经典ASP中Request.Form的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:50