zl程序教程

您现在的位置是:首页 >  后端

当前栏目

ASP中Split分割字符串函数的实例用法

实例ASP 函数 字符串 用法 分割 split
2023-06-13 09:14:47 时间

ASP中Split函数的用法
分割截取字符串
看几个例子就能理解了

复制代码代码如下:


mystr="1,2,3,4,5"
mystr=split(mystr,",")
fori=0toubound(mystr)
response.writemystr(i)
next 
"返回值为123456

mystr="xlei.net/http/student/x/index.asp"
mystr=split(mystr,"/http/student")
fori=0toubound(mystr)
response.writemystr(i)
next 
"返回值为xlei.net/x/index.asp

mystr="1批在2批在3批在4批是在5批在"
mystr=split(mystr,"批在")
fori=0toubound(mystr)
response.writemystr(i)
next 
"返回值为1234批是在56


描述
返回基于0的一维数组,其中包含指定数目的子字符串。
语法
Split(expression[,delimiter[,count[,start]]])
Split函数的语法有以下参数:

参数描述
expression必选。字符串表达式,包含子字符串和分隔符。如果expression为零长度字符串,Split返回空数组,即不包含元素和数据的数组。
delimiter可选。用于标识子字符串界限的字符。如果省略,使用空格("")作为分隔符。如果delimiter为零长度字符串,则返回包含整个expression字符串的单元素数组。
count可选。被返回的子字符串数目,-1指示返回所有子字符串。
compare可选。指示在计算子字符串时使用的比较类型的数值。有关数值,请参阅“设置”部分。

设置
compare参数可以有以下值:
常数值描述
vbBinaryCompare0执行二进制比较。
vbTextCompare1执行文本比较。
vbDatabaseCompare2执行基于数据库(在此数据库中执行比较)中包含的信息的比较。

引用来自asp端验证是否包含非法字符

复制代码代码如下:


username=replace(trim(request.form("username")),""","""")
password=replace(trim(request.form("password")),""","""")

ifinstr(username,"%")orinstr(username,"#")orinstr(username,"?")orinstr(username,"|")then
    response.write"<script.language=javascript>alert("您的姓名含有非法字符!");history.back()</script>"
    response.end
    endif
ifinstr(password,"%")orinstr(password,"#")orinstr(password,"?")orinstr(password,"|")then
    response.write"<script.language=javascript>alert("您的密码含有非法字符!");history.back()</script>"
response.end
endif