Click here to Skip to main content
11,639,554 members (64,963 online)
Click here to Skip to main content

High Speed String Concatenation Using VBScript

, 13 Apr 2007 CPOL 17.6K 8
Rate this:
Please Sign up or sign in to vote.
It has been said that large scale creation of long strings from small strings is not practical in VBScript - NOT SO


Some time ago, I posted about high speed string concatenation in JScript, here is the VBScript equivalent.

This post is not really a full post. Don't jump to give it a -1 rating. This is here as an addendum to a previous article which - in great detail - shows the thinking behind this but uses JScript. To get the background, go here.

Below is the code. The only real difference between this and the JScript is that in VBScript, arrays are not objects. This means that I have had to create an explicit class to create the objects for the linked list that holds the string fragments. Also please note that in VBScript, arrays are of fixed length. If you redim an array, you actually perform a copy operation (the old one is thrown away and you get a new array). This means that the split/join technique discussed in the messages with the JScript post cannot work in VBScript.

class XLink
    public datum
    public nextXLink
    private sub Class_Initialize
      set nextXLink=nothing
    end sub
end class

class FStringCat
    private sp
    private ep
    private l
    private accum

    private sub Class_Initialize
        set sp=nothing
    end sub
    public sub push(what)
        accum=accum & what
        if len(accum)>2800 then
            if(sp is nothing) then
                set ep=new XLink
                set sp=ep
                dim oep
                set oep=ep
                set ep=new XLink
                set oep.nextXLink=ep
            end if
        end if
    end sub
    public function toString()
        if l=0 then
            exit function
        end if
        ep.datum=ep.datum & accum
        while l>1 
            dim ptr
            set ptr=sp
            dim nsp
            set nsp=new XLink
            dim nep
            set nep=nsp
            dim nl
            while not (ptr is nothing) 
                if  nep.datum=""  then
                    if ptr.datum<>"" then nep.datum=nep.datum & ptr.datum
                    set nep.nextXLink=new XLink
                    set nep=nep.nextXLink
                end if
                set ptr=ptr.nextXLink
            set sp=nsp
            set ep=nep
    end function
end class

' Some example code
dim ts
set ts=new FStringCat
WScript.echo("Created FStringCat")
dim i
for i=1 to 1000
    ts.push("Hi there: " & i & vbcrlf)

The original nerds-central post is here. For more like this, check out Nerds-Central.


  • 13th April, 2007: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

alex turner
Web Developer
United Kingdom United Kingdom
I am now a Software Systems Developer - Senior Principal at Micro Focus Plc. I am honoured to work in a team developing new compiler and runtime technology for Micro Focus.

My past includes a Ph.D. in computational quantum mechanics, software consultancy and several/various software development and architecture positions.

For more - see



You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150731.1 | Last Updated 13 Apr 2007
Article Copyright 2007 by alex turner
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid