ASP中Split函數的用法,用split分割截取字符串,看幾個例子就能理解了
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