Solved

# VBScript - Concatenate Mulltiple Lines

Posted on 2011-10-18
491 Views
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).

Thanks.
0
Question by:1500orion

LVL 74

Expert Comment

Where does the data come from? An existing string variable? Read from a file?
0

Author Comment

This would come from a read of a text file.
0

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

If counter Mod 8 = 0 Then
output.WriteLine(accumulator)
accumulator = ""
End If

counter = counter + 1
Wend

If counter Mod 8 <> 0 Then
output.WriteLine(accumulator)
End If

output.Close
input.Close


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

## Featured Post

### Suggested Solutions

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) 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 (http://www.enterprise.efax.com), 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.