Solved

# VBScript - Concatenate Mulltiple Lines

Posted on 2011-10-18
Medium Priority
507 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
• 2

LVL 75

Expert Comment

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

Author Comment

ID: 36989642
This would come from a read of a text file.
0

LVL 75

Accepted Solution

käµfm³d   👽 earned 2000 total points
ID: 36989709
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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…