Fast VBScript string class

Fast VBScript string class
by Jan Verhoeven, 10 November 2001


String building in VBScript is very slow. The VBScript class presented below is easy to use and much faster. 

<%
  
'fast string class
  class strCat
    
dim index, ub, ar()

    
Private Sub Class_Initialize()
      
'statements
      redim ar(50)
      index
=0
      ub
=10
    
End Sub

    
Private Sub Class_Terminate()
      
'statements
      erase ar
    
End Sub

    
public default Sub Add(value)
      ar(index)
=value
      index
=index+1
      
if index>ub then
        ub
=ub+50
        
redim preserve ar(ub)
      
end if
    
end sub

    
public Function dump
      
redim preserve ar(index-1)
      dump
=join(ar,"")
    
end function
  
end class

  
'first traditional method
  t1=time
  os
=""
  
for i=1 to 5000
    os
=os & "This is the slow method of building strings"
  
next
  t2
=time

  t3
=time
  
set cat= new strCat
  
for i=1 to 5000
    cat(
"This is the slow method of building strings")
  
next
  s
= cat.dump
  
set cat = nothing
  t4
=time

  response.Write(
"Using the & operator:" & cstr(t1) & " - " & cstr(t2) &  "<br>Using the fast string class: " & cstr(t3) &  " -  cstr(t4) &  "<br>")
%>

Using strCat
First create a new instance of the class with:

  set cat= new strCat

Next you add add substrings:

  cat("add some substring to the fast string class")
  cat("add another substring to the fast string class")

When you are done dump the result string and release the object:

  s=cat.dump
  set cat=nothing

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值