dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Apr 24, 2001

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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)
Guoran Xie
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date