加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码网 (https://www.900php.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

数组操作类 - ASP教程

发布时间:2016-08-06 15:52:02 所属栏目:Asp教程 来源:站长网
导读:Option Explicit Class cArr Private tMin ''//最小值 thisMin Private tMax ''//最大值 Private tStr ''//数组串 Private tSortStr''//排序串,当对同一数组串
Option Explicit

Class cArr
     Private tMin      ''//最小值 thisMin
     Private tMax      ''//最大值
     Private tStr      ''//数组串
     Private tSortStr''//排序串,当对同一数组串进行操作时避免多次排序操作
     Private tLength      ''//元素个数

     Private Sub Class_Initialize
           tMin      =0
           tMax      =0
           tStr      ="0"
           tLength      =0
           tSortStr=""
     End Sub

     ''//获得最小值
     Property Get cMin
           If tMin=0 Then
                 Dim sStr
                 If tSortStr="" Then
                       sStr=Split(cSort,",")
                 Else
                       sStr=Split(tSortStr,",")
                 End If
                 tMin=sStr(0)
           End If
           cMin=tMin
     End Property

     ''//获得最大值
     Property Get cMax
           If tMax=0 Then
                 Dim sStr
                 If tSortStr="" Then
                       sStr=Split(cSort,",")
                 Else
                       sStr=Split(tSortStr,",")
                 End If
                 tMax=sStr(Ubound(sStr))
           End If
           cMax=tMax
     End Property

     Property Get Length
           If tStr="" Or tStr=0 Then
                 Length      =0
           Else
                 tLength      =Ubound(Split(tStr,","))+1
                 Length      =tLength
           End If
     End Property

     ''//将数组串赋给属性
     Property Let srcStr(str)
           If str="" Then
                 tStr="0"
           Else
                 tStr=str
           End If
     End Property

     ''//排序,倒序
     Public Function cSort
           Dim Arr,i
           Redim Arr(Ubound(Split(tStr,",")))
           Dim tmp,j
           For i=0 to Ubound(Arr)
                 Arr(i)=CDBL(Split(tStr,",")(i))
           Next
           For I= 0 to Ubound(Arr)
                 For  j=i+1 to Ubound(Arr)
                       If Arr(i)<Arr(j) Then
                             tmp      =Arr(i)
                             Arr(i)      =Arr(j)
                             Arr(j)      =tmp
                       End If
                 Next
           Next
           tSortStr=Join(Arr,",")
           cSort=tSortStr
     End Function
   
     ''//顺序
     Public Function cSortAsc
           Dim tmp,i,Arr
           If tSortStr="" Then
                 tmp=cSort
           Else
                 tmp=tSortStr
           End If
           Redim Arr(Ubound(Split(tmp,",")))
           Arr=Split(tmp,",")
           For i= Ubound(Arr) to 0 Step -1
                 cSortAsc=cSortAsc & Arr(i) & ","
           Next
           cSortAsc=Left(cSortAsc,Len(cSortAsc)-1)
     End Function

     ''//在未尾加元素
     Public Function AddItem(str)
           If tStr="" OR tStr="0" Then
                 tStr=str
           Else
                 tStr=tStr & "," & str
           End If
           tMin      =0
           tMax      =0
           tSortStr=""
           tLength      =tLength + 1
           AddItem      =tStr
     End Function

     ''//前部加元素
     Public Function AddItemBefore(str)
           If tStr="" OR tStr="0" Then
                 tStr=str
           Else
                 tStr=str & "," & tStr
           End If
           tMin      =0
           tMax      =0
           tSortStr=""
           tLength      =tLength + 1
           AddItemBefore=tStr
     End Function

     ''//移除元素
     Public Function RemoveItem(str)
           tStr      =Replace("," & tStr & "," , "," & str & "," , ",")
           tStr      =Mid(tStr,2,Len(tStr)-2)
           tMin      =0
           tMax      =0
           tSortStr=Replace("," & tSortStr & "," , "," & str & "," , ",")
           tSortStr=Mid(tSortStr,2,Len(tSortStr)-2)
           tLength      =0
           RemoveItem=tStr
     End Function

     ''//在索引位置加元素
     Public Function AddItemI(index,str)
           If index>=Length Then
                 AddItem(str)
                 Exit Function
           End If
           If index<=0 Then
                 AddItemBefore(str)
                 Exit Function
           End if
         
           Dim Arr,i,tmps
           Redim Arr(Ubound(Split(tStr,",")))
           Arr=Split(tStr,",")
           For i=0 to index-1
                 tmps=tmps & Arr(i) & ","
           Next
           tmps=tmps & str & ","
           For i=index to Ubound(Arr)
                 tmps=tmps & Arr(i) & ","
           Next
           tmps      =Left(tmps,Len(tmps)-1)
           tStr      =tmps
           tSortStr=""
           tLength      =tLength+1
           tMin      =0
           tMax      =0
           AddItemI=tStr
     End Function

     ''//在索引位置移除元素
     Public Function RemoveItemI(index)
           If index>=Length Or index<=0 Then
                 Exit Function
           End If
         
           Dim Arr,i,tmps
           Redim Arr(Ubound(Split(tStr,",")))
           Arr=Split(tStr,",")
           For i=0 to Ubound(Arr)
                 If i<>index Then tmps=tmps & Arr(i) & ","
           Next
           tmps=tmps & str & ","
           tmps      =Left(tmps,Len(tmps)-1)
           tStr      =tmps
           tSortStr=""
           tLength      =0
           tMin      =0
           tMax      =0
           RemoveItemI=tStr
     End Function

End Class

(编辑:源码网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读