really really slow by nature. This sample code uses classes to speed up the process by ten times. Someone recentally came up with a DLL to do this but not all of us can install a DLL on our ISP's web servers so I wrote this easy to use VB Class for handling string concatenation.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
Terms of Agreement:
By using this code, you agree to the following terms...
- You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.
- You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this code from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
'**************************************
' Name: StrCat - Non DLL version
' Description:ASP's ability to concatena
' ting many strings together is really rea
' lly slow by nature. This sample code use
' s classes to speed up the process by ten
' times. Someone recentally came up with a
' DLL to do this but not all of us can ins
' tall a DLL on our ISP's web servers so I
' wrote this easy to use VB Class for hand
' ling string concatenation.
' By: Kevin Pirkl
'
' Inputs:Public Property Length - To res
' ize the string length. To use it a secon
' d time on another string just set the .L
' ength property to another value or just
' dereference the object and recreate it.
Public Method Add - too add data to the concatenated string.
'
' Assumes:Didnt do much testing except u
' sing it to add together a string of 100,
' 000 characters and it took about 7 secon
' ds which is not bad. If you need to add
' together more than that dont use this. I
' f your catting char strings like "
1<tr '="">" + whatever then it should be ok.
2'
3'This code is copyrighted and has ' limited warranties.Please see http://w
4' ww.Planet-Source-Code.com/xq/ASP/txtCode
5' Id.6342/lngWId.4/qx/vb/scripts/ShowCode.
6' htm 'for details. '**************************************
7
8Set X = New strCat' Create an instance of strCat
9X.Length = 100001' Change from the default String length of 100,000
10str = ""
11For I = 1 To X.Length
12X.Add("A") '- takes 7 seconds on my computer
13'str = str & "A"'- takes 1 minute 7 seconds on my computer
14Next
15msgBox(Len(X.Value))
16X.Length = 101
17For I = 1 To X.Length
18X.Add("B")
19Next
20msgBox(Len(X.Value))
21Set X = Nothing ' Destroy the instance.
22msgBox("Done")
23Class strCat
24Private IntCntr
25Private strArray()
26Private intLength
27Public Property Get Length
28Length = intLength
29End Property
30Public Property Let Length( ByVal intLen)
31intLength = intLen
32IntCntr = 0
33Redim strArray(1)
34strArray(0) = ""
35Redim strArray(intLength)
36End Property
37Public Property Get Value
38Value = Join( strArray,"")
39End Property
40Private Sub Class_Initialize()
41IntCntr = 0
42Length = 100000
43End Sub
44Public Function Add( strToAdd)
45strArray(IntCntr) = strToAdd
46IntCntr= IntCntr + 1
47End Function
48End Class</tr>