arrClass.asp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <%
  2. '***************************************************************************
  3. ' 创 建 人:cuiwl (longchengfy@hotmail.com)
  4. ' 更新时间:2006-12-3 4:09
  5. ' 说 明:二维数组操作
  6. ' 数组多作为方便有效的存储实体
  7. ' 与数据库的操作相类似,一维字段名成,二维记录
  8. ' str = "issys:1"&chr(10)&"user:1,2,4,3"
  9. '***************************************************************************
  10. class arrayoperate
  11. public mark1,mark2,uarr
  12. public n, m
  13. private sub class_initialize()
  14. mark1 = ";"
  15. mark2 = chr(10)
  16. n = 0
  17. m = 1
  18. end sub
  19. private sub class_terminate()
  20. end sub
  21. ' 将相应的的 字符串 转换为二维数组
  22. public function stringtoarray(byval strpar)
  23. dim arr1,arr2,arr
  24. dim i
  25. arr2 = split(strpar,mark2)
  26. redim arr(3,ubound(arr2))
  27. for i=0 to ubound(arr2)
  28. strpar = arr2(i)
  29. arr1 = split(strpar,mark1)
  30. redim preserve arr1(6)
  31. arr(0,i) = arr1(6)
  32. arr(1,i) = arr1(4)
  33. arr(2,i) = arr1(1)
  34. next
  35. stringtoarray = arr
  36. uarr = ubound(arr2)
  37. end function
  38. '删除条件为第n个子元素等于key的二维数组元素
  39. public function arrayremove(byval arrpar, byval key)
  40. dim i,j,k
  41. k=0
  42. for i = 0 to ubound(arrpar,2)
  43. if arrpar(n,i) <> key then
  44. k = k+1
  45. for j = 0 to ubound(arrpar,1)
  46. arrpar(j,k-1) = arrpar(j,i)
  47. next
  48. end if
  49. next
  50. ReDim Preserve arrpar(2, k-1)
  51. arrayremove = arrpar
  52. end function
  53. '返回条件为第n个子元素等于key的二维数组元的第m个子元素的值
  54. public function arrayvalue(byval arrpar, byval key)
  55. dim i,j
  56. j = 0
  57. for i = 0 to ubound(arrpar,2)
  58. if arrpar(n,i) = key then
  59. j = j + 1
  60. arrayvalue = arrpar(m,i)
  61. end if
  62. next
  63. if j > 1 then arrayvalue = j
  64. end function
  65. end class
  66. '***************************************************************************
  67. ' 调用示例
  68. 'dim objarray: set objarray = new arrayoperate
  69. 'stringtoarray method:
  70. ' strvar = "issys:1"&chr(10)&"user:1,2,4,3"
  71. ' objarray.mark1=":"
  72. ' objarray.mark2=chr(10)
  73. ' ? = objarray.stringtoarray("strvar")
  74. 'arrayremove method:
  75. ' objarray.n = 0
  76. ' ? = objarray.arrayremove(arrpar,key)
  77. 'arrayvalue method:
  78. ' objarray.n = 0
  79. ' objarray.m = 1
  80. ' ? = objarray.arrayvalue(arrpar,key)
  81. 'set arrayoperate = nothing
  82. %>