Tools Links Login

Improved String Concatenation Performance

Joining strings together, or concatentation, can take a toll on performance. Especially in a long loop. Here is a method to increase performance by 20x.

Sub Concat(Dest As String, Source As String)
'First Dest must have one space more
'Example : Dest = 'Hello '
'and not Dest = 'Hello'

   Dim string1 As Long
   Dim string2 As Long
   
   string1 = Len(Dest)
   string2 = Len(Source)

   Dest = Dest & Space$(string2)
      
   Mid$(Dest, string1, string2) = Source
End Sub

About this post

Posted: 2019-08-25
By: ZeljkoBijelic
Viewed: 231 times

Categories

Visual Basic 6

Attachments

No attachments for this post

Special Instructions

This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.