VBScript - Concatenate Mulltiple Lines

Posted on 2011-10-18
Last Modified: 2012-05-12
I am looking for a way to string data together based on line counts with VBScript.  Every 8 lines should be concatenated into one line.  There is no unique delimiter in the data; just grab every 8 lines and concatenate into a single line.  Something like:

for i = 1 to 8 (where these would dynamically change, next loop through 9 to 17, etc).  

Question by:1500orion
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    Where does the data come from? An existing string variable? Read from a file?

    Author Comment

    This would come from a read of a text file.
    LVL 74

    Accepted Solution

    Here's an example:

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set input = fso.OpenTextFile("C:\path\to\file.txt", 1, True)  ' 1 = For Reading
    Set output = fso.OpenTextFile("C:\path\to\result.txt", 2, True)  ' 2 = For Writing
    counter = 1
    While Not input.AtEndOfStream
        accumulator = accumulator & input.ReadLine()
        If counter Mod 8 = 0 Then
            accumulator = ""
        End If
        counter = counter + 1
    If counter Mod 8 <> 0 Then
    End If

    Open in new window

    I dumped the results to another file, but you can change this accordingly.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This is an addendum to the following article: Acitve Directory based Outlook Signature ( The script is fine, and works in normal client-server domains…
    Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now