?
Solved

VBScript - Concatenate Mulltiple Lines

Posted on 2011-10-18
3
Medium Priority
?
507 Views
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).  

Thanks.
0
Comment
Question by:1500orion
  • 2
3 Comments
 
LVL 75

Expert Comment

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

Author Comment

by:1500orion
ID: 36989642
This would come from a read of a text file.
0
 
LVL 75

Accepted Solution

by:
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
    accumulator = accumulator & input.ReadLine()
    
    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

Open in new window


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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

840 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