加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

数组 – 如何在经典asp中拆分字符串

发布时间:2020-12-16 06:40:16 所属栏目:asp.Net 来源:网络整理
导读:我试图在经典的asp应用程序中拆分一个字符串,在页面中有下面的代码,它似乎不起作用.还有一个问题看起来很相似但是处理不同类型的问题,我已经找到了那里的答案而且他们没有帮助.任何帮助,将不胜感激. % Dim SelectedCountries,CitizenshipCountry,Count Selec
我试图在经典的asp应用程序中拆分一个字符串,在页面中有下面的代码,它似乎不起作用.还有一个问题看起来很相似但是处理不同类型的问题,我已经找到了那里的答案而且他们没有帮助.任何帮助,将不胜感激.

<% 
Dim SelectedCountries,CitizenshipCountry,Count 
SelectedCountries = "IN,CH,US"    
CitizenshipCountry = Split(SelectedCountries,",")
Count = UBound(CitizenshipCountry) + 1 
Response.Write(CitizenshipCountry[0])
Response.End
%>

解决方法

你犯了几个错误,这就是为什么你没有得到预期的结果.

>检查数组的边界时,需要指定Array变量,在本例中为Split()生成的变量,即CitizenshipCountry.
>通过在括号中指定元素序号位置((…))而不是方括号([…])来访问数组元素.

试试这个:

<% 
Dim SelectedCountries,")
'Get the count of the array not the string.
Count = UBound(CitizenshipCountry)
'Use (..) when referencing array elements.
Call Response.Write(CitizenshipCountry(0))
Call Response.End()
%>

我喜欢做的是在调用UBound()之前使用IsArray检查变量是否包含有效数组以避免这些类型的错误.

<% 
Dim SelectedCountries,")
'Get the count of the array not the string.
If IsArray(CitizenshipCountry) Then
  Count = UBound(CitizenshipCountry)
  'Use (..) when referencing array elements.
  Call Response.Write(CitizenshipCountry(0))
Else
  Call Response.Write("Not an Array")
End If
Call Response.End()
%>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读