Library tutorials & articles
String Concatenation Component
- Introduction
- The solution
- The results
- Conclusion
- Test Code
Introduction
I wrote this component - StrCat.Catter - because string concatenation
in Visual Basic (Script) has poor performance characteristics. I found that code
like this:
<%
Dim rs
Set rs = ExecuteSql("SELECT Username FROM Users")
Dim some_str
some_str = ""
do until rs.EOF
some_str = some_str & rs(0) & "<br>" & vbCrLf
rs.MoveNext
loop
Response.Write some_str
%>
|
performed very poorly. The code took a long time to execute, during which time the processor was totally saturated. I found articles on MSDN stating that this type of code was a bad idea, and I've heard that this type of concatenation results in run times that are proportional to the square of the number of concatenations.
Related articles
Related discussion
-
Web Development Business Partners
by James Crowley (4 replies)
-
Classic ASP : Page expires
by HelpTechIT (1 replies)
-
IT Service Desk Analyst
by aniamodis (0 replies)
-
Can somebody help: CAsyncSOcket class (Client-server networking)
by chong (5 replies)
-
ASP - PHP - JSP ... which is better?
by daryljamesod (3 replies)
Related podcasts
-
ASP.NET Caching and Performance
Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...
Events coming up
-
Jun
16
Code Generation 2009
Cambridge, United Kingdom
A developer event with a practical focus on helping people get to grips with code generation tools and technologies.
A great idea! You can also reduce concatenation times by using arrays and the built-in Join() function. No components required. Similar performance gain. Very readable syntax (once you understand the Join arguments).
StringVar = JOIN( StringArray(), ElementSeparatorText )
Redim S(4)
S(0) = "This is text line 1"
S(1) = "This is text line 2"
S(2) = "This is text line 3"
S(3) = "This is text line 4"
S(4) = "This is text line 5"
'assign lines to string variable with comma separator
vMyString = join(S, ",")
'dump lines to screen, one element per visual line ("&" executes once)
response.write join(S, "<br>" & VbCrLf)
'output array as a table row (elements are separated with "</td><td>")
response.write "<tr><td>" & join(S, "</td><td>" ) & "</td></tr>"
'build an option list of codes that exist in a database
set rs = CreateObject("ADOR.Recordset")
rs.Open "select [TypeCode] from [CodeTable] order by [TypeCode]", myConnectString, adOpenStatic
S = rs.getrows '<-- very fast!
rs.close
response.write = "<select ...>" & vbcrlf
response.write = "<option>" & join(S, "</option>" & vbcrlf & "<option>" ) & "</option>" & vbcrlf
response.write = "</select>" & vbcrlf
'clear array from memory (if you want to free up memory right away)
erase S
This thread is for discussions of String Concatenation Component.