Use Mid$ to Compose a Big String

Use Mid$ to Compose a Big String

The following code is a fast way to compose a big string by using Mid$ function instead of using the concatenating operator. The strings concatenated in a loop are often variable. So use S1 to represent general case.

     Const AllocFactor = 100000    Dim S As String    Dim S1 As String    Dim tmp As String    Dim i As Long    Dim StrLen As Long    Dim MaxLen As Long    Dim Curpos As Long    Dim CurLen As Long    MaxLen = AllocFactor    S = Space(MaxLen)    Curpos = 1    S1 = "abc"    For i = 0 To 99999        StrLen = Len(S1)        CurLen = Curpos + StrLen - 1        If CurLen > MaxLen Then            tmp = S            S = Space(MaxLen + AllocFactor)            Mid$(S, 1, MaxLen) = tmp            MaxLen = MaxLen + AllocFactor        End If        Mid$(S, Curpos, StrLen) = S1        Curpos = CurLen + 1    Next    If CurLen < MaxLen Then S = Left$(S, CurLen)

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved