Improved String Concatenation Performance

By | 2019-08-25

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

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.