Chức năng: Tách chuổi ký tự dựa vào một chuổi xác định
Ngôn ngữ: asp - Nhóm: array
CÚ PHÁP
arrayOfStrings = SplitRegExp(stringInput, stringPattern, boolIgnoreCase)
Sử dụng để tách chuổi ký tự thành một mảng dựa vào một hoặc chuổi ký tự xác định trong chuổi ban đầu.
VÍ DỤ
<%
dim s, arr, element
s = "grgrg~|~item2bcs~|~item3~|~item4~|~d~|~sds"
arr = SplitRegExp(s, "\~\|\~", true)
response.write s & "<BR><BR>"
for each element in arr
response.write element & "<BR>"
next
'returns:
'
' "grgrg~|~item2bcs~|~item3~|~item4~|~d~|~sds"
'
' "grgrg"
' "item2bcs"
' "item3"
' "item4"
' "d"
' "sds"
%>
ASP Code
<%
function SplitRegExp(byval sInput, byval sPattern, byval bIgnoreCase)
dim re, matches, match, hStart, hEnd, i
Set re = new regexp
re.pattern = sPattern
re.ignorecase = bIgnoreCase
re.global = true
if not re.test(sInput) then
splitregexp = array(sInput)
set re = nothing
exit function
end if
set matches = re.execute(sInput)
hStart = 0
redim arr(matches.count)
i = 0
for each match in matches
hEnd = match.firstindex
arr(i) = mid(s, hStart+1, hEnd - hStart)
hStart = match.firstindex + match.length
i = i + 1
next
arr(ubound(arr)) = mid(s, hStart+1)
set matches = nothing
Set re = nothing
splitregexp = arr
end function
%>