代码如下:
<BR /><%'******************************************************* <BR />'过滤数组重复函数名称:array_no(cxstr1,cxstr2,cxstr3) <BR />'cxstr1:任意的字符串,自动识别 <BR />'cxstr2:cxstr1中分割符号。 <BR />'cxstr3:提取结果中的某一位置字串,等于0时返回为全部,大于数组下标时返回最后. <BR />'使用于二维数组 <BR />'******************************************************* <BR />function array_no(cxstr1,cxstr2,cxstr3) <BR />if len(cxstr3) > 0 then <BR />if not IsNumeric(cxstr3) then <BR />array_no = "对不起,参数3类型必需为数字" <BR />Exit Function <BR />end if <BR />else <BR />array_no = "对不起,参数3类型必需为数字" <BR />Exit Function <BR />end if <BR />if isarray(cxstr1) then <BR />array_no = "对不起,参数1不能为数组" <BR />Exit Function <BR />end if <BR />if cxstr1 = "" or isempty(cxstr1) then <BR />array_no = "没有数据" <BR />Exit Function <BR />end if <BR />ss = split(cxstr1,cxstr2) <BR />cxs=cxstr2&ss(0)&cxstr2 <BR />sss=cxs <BR />for m = 0 to ubound(ss) <BR />cc = cxstr2&ss(m)&cxstr2 <BR />if instr(sss,cc)=0 then <BR />sss = sss&ss(m)&cxstr2 <BR />end if <BR />next <BR />array_no = right(sss,len(sss)-len(cxstr2)) <BR />array_no = left(array_no,len(array_no)-len(cxstr2)) <BR />if cxstr3 <> 0 then <BR />cx_sp = split(array_no,cxstr2) <BR />if cxstr3 > ubound(cx_sp) then <BR />array_no = cx_sp(ubound(cx_sp)) <BR />else <BR />array_no = cx_sp(cxstr3) <BR />end if <BR />end if <BR />end function%> <BR /> <br /><br />下面是测试代码: <BR /><span><U></U></span> 代码如下:<BR /><%s1 = "abc,aa,bb,cdef,bc,abcdef,hhgg,gggg,cde,edc" <BR />s2 = "1,2,3,11,22,33,12,13,14,11,33,333,14" <BR />s3 = "" <BR />s4 = "sdf,abc,12,2,2,abc" <BR />s5 = split(s4) <BR />response.write "字串为字符时:"&array_no(s1,",",0)&"<br>" <BR />response.write "字串为数字时:"&array_no(s2,",",0)&"<br>" <BR />response.write "字串为空时:"&array_no(s3,",",0)&"<br>" <BR />response.write "字串为混合时:"&array_no(s4,",",0)&"<br>" <BR />response.write "字串为数组时:"&array_no(s5,",",0)&"<br>" <BR />response.write "字串为未知变量时:"&array_no(s33,",",0)&"<br>" <BR />response.write "提取某一位时,没有超过下标时:"&array_no(s1,",",2)&"<br>" <BR />response.write "提取某一位时,超过下标时:"&array_no(s1,",",200)&"<br>"%> <BR /> <BR />测试结果: <BR /><span><U></U></span> 代码如下:<BR />字串为字符时:abc,aa,bb,cdef,bc,abcdef,hhgg,gggg,cde,edc <BR />字串为数字时:1,2,3,11,22,33,12,13,14,333 <BR />字串为空时:没有数据 <BR />字串为混合时:sdf,abc,12,2 <BR />字串为数组时:对不起,参数1不能为数组 <BR />字串为未知变量时:没有数据 <BR />提取某一位时,没有超过下标时:bb <BR />提取某一位时,超过下标时:edc <BR /> <br /><br /><STRONG>硕编程增强版本:</STRONG> 解决了数组常见错误<BR /><span><U></U></span> 代码如下:<BR /><% <BR />'******************************************************* <BR />'过滤数组重复函数名称:array_no(cxstr1,cxstr2,cxstr3) <BR />'cxstr1:任意的字符串,自动识别 <BR />'cxstr2:cxstr1中分割符号。 <BR />'cxstr3:提取结果中的某一位置字串,等于0时返回为全部,大于数组下标时返回最后. <BR />'使用于二维数组 <BR />'******************************************************* <BR />function array_no(cxstr1,cxstr2,cxstr3) <BR />if len(cxstr3) > 0 then <BR />if not IsNumeric(cxstr3) then <BR />array_no = "对不起,参数3类型必需为数字" <BR />Exit Function <BR />end if <BR />else <BR />array_no = "对不起,参数3类型必需为数字" <BR />Exit Function <BR />end if <BR />if isarray(cxstr1) then <BR />array_no = "对不起,参数1不能为数组" <BR />Exit Function <BR />end if <BR />if cxstr1 = "" or isempty(cxstr1) then <BR />array_no = "没有数据" <BR />Exit Function <BR />end if <BR />do while instr(cxstr1,",,")>0 <BR />cxstr1=replace(cxstr1,",,",",") <BR />loop <BR />if right(cxstr1,1)="," then <BR />cxstr1=left(cxstr1,len(cxstr1)-1) <BR />end if <BR />ss = split(cxstr1,cxstr2) <BR />cxs=cxstr2&ss(0)&cxstr2 <BR />sss=cxs <BR />for m = 0 to ubound(ss) <BR />cc = cxstr2&ss(m)&cxstr2 <BR />if instr(sss,cc)=0 then <BR />sss = sss&ss(m)&cxstr2 <BR />end if <BR />next <BR />array_no = right(sss,len(sss)-len(cxstr2)) <BR />array_no = left(array_no,len(array_no)-len(cxstr2)) <BR />if cxstr3 <> 0 then <BR />cx_sp = split(array_no,cxstr2) <BR />if cxstr3 > ubound(cx_sp) then <BR />array_no = cx_sp(ubound(cx_sp)) <BR />else <BR />array_no = cx_sp(cxstr3) <BR />end if <BR />end if <BR />end function <br /><br />s1 = "abc,aa,bb,cdef,bc,abcdef,hhgg,gggg,cde,edc,333,,,,,333,7,,,," <BR />s2 = "1,2,3,11,22,33,12,13,14,11,33,333,14,333,,,,,333,7,,,," <BR />s3 = "" <BR />s4 = "sdf,abc,12,2,2,abc,333,,,,,333,7,,,," <BR />s5 = split(s4) <BR />response.write "字串为字符时:"&array_no(s1,",",0)&"<br>" <BR />response.write "字串为数字时:"&array_no(s2,",",0)&"<br>" <BR />response.write "字串为空时:"&array_no(s3,",",0)&"<br>" <BR />response.write "字串为混合时:"&array_no(s4,",",0)&"<br>" <BR />response.write "字串为数组时:"&array_no(s5,",",0)&"<br>" <BR />response.write "字串为未知变量时:"&array_no(s33,",",0)&"<br>" <BR />response.write "提取某一位时,没有超过下标时:"&array_no(s1,",",2)&"<br>" <BR />response.write "提取某一位时,超过下标时:"&array_no(s1,",",200)&"<br>" <BR />%> <BR /> <BR />主要是增加了判断 <BR /><span><U></U></span> 代码如下:<BR />do while instr(cxstr1,",,")>0 <BR />cxstr1=replace(cxstr1,",,",",") <BR />loop <BR />if right(cxstr1,1)="," then <BR />cxstr1=left(cxstr1,len(cxstr1)-1) <BR />end if <BR />
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!