截取字符菜鸟问题~~
我有的数据库表中的字段值有这样一个字符串~~
例如:1,0,1,0,1,0,1,0 或
1|0|1|0|1|0|1|0 或
1a0b1c0d1e0f1g0h
我想取得每一个字符的值,也就是把这些字符串分解开,分别去值。
分解得到的结果为:
no1=1
no2=0
no3=1
no4=0
no5=1
no6=0
no7=1
no8=0
请各位大虾帮忙解决~~
最好使用function自定义函数解决~~
谢谢,在线期待中。。。。。。
------解决方案--------------------前两种可以使用split
------解决方案--------------------用split函数,split(字符串, 分隔符),结果是一个数组
------解决方案--------------------returnstr=split(sqlstr, ", ")
For i=LBound(returnstr) To UBound(returnstr)
response.write returnstr(i)
Next
------解决方案-------------------- <%
Dim str
dim ary
str = "1a0b1c0d1e0f1g0h "
ary = SplitString(str)
ShowAry(ary)
str = "1,0,1,0,1,0,1,0 "
ary = SplitString(str)
ShowAry(ary)
str = "1|0|1|0|1|0|1|0 "
ary = SplitString(str)
ShowAry(ary)
sub ShowAry(byval ary)
for i= 0 to ubound(ary)
Response.Write(ary(i)& " <BR> ")
next
Response.Write( " <HR> ")
end sub
Function SplitString(byval str)
Dim reg
set reg = new RegExp
reg.Pattern = "[^\d]* "
reg.Global = true
str = reg.Replace(str, ", ")
set reg = nothing
SplitString = split(str, ", ")
End Function
%>
------解决方案--------------------正则.