17370845950

ASP中Split分割字符串函数的实例用法小结
目录
  • ASP中Split函数的用法
    • 分割截取字符串
    • 描述
    • 语法
    • 参数 描述
    • 设置
  • 引用来自 asp端验证是否包含非法字符

    ASP中Split函数的用法

    分割截取字符串

    看几个例子就能理解了

    mystr="1,2,3,4,5"
    mystr=split(mystr,",")
    for i=0 to ubound(mystr)
    response.write mystr(i)
    next 
    '返回值为123456
    mystr="xlei.net/http/student/x/index.asp"
    mystr=split(mystr,"/http/student")
    for i=0 to ubound(mystr)
    response.write mystr(i)
    next 
    '返回值为xlei.net/x/index.asp
    mystr="1批在2批在3批在4批是在5批在"
    mystr=split(mystr,"批在")
    for i=0 to ubound(mystr)
    response.write mystr(i)
    next 
    '返回值为1234批是在56

    描述

    返回基于 0 的一维数组,其中包含指定数目的子字符串。

    语法

    Split(expression[, delimiter[, count[, start]]])

    Split 函数的语法有以下参数:

    参数 描述

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

    设置

    compare 参数可以有以下值:
    常数 值 描述
    vbBinaryCompare 0 执行二进制比较。
    vbTextCompare 1 执行文本比较。
    vbDatabaseCompare 2 执行基于数据库(在此数据库中执行比较)中包含的信息的比较。

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

    username=replace(trim(request.form("username")),"'","''")
    password=replace(trim(request.form("password")),"'","''")
    if instr(username,"%") or instr(username,"#") or instr(username,"?") or instr(username,"|") then
         response.write "<script. language=javascript>alert('您的姓名含有非法字符!');history.back()</script>"
         response.end
         end if
    if instr(password,"%") or instr(password,"#") or instr(password,"?") or instr(password,"|") then
         response.write "<script. language=javascript>alert('您的密码含有非法字符!');history.back()</script>"
    response.end
    end if