Fast VBScript String Class

Source: Internet
Author: User
Fast VBScript String Class
by Jan Verhoeven, November 2001


String building in VBScript is very slow. The VBScript class presented below are 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")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.