Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Group data from text file

I have a routine where I'm reading a text file into a list in the code below.

I need to modify this so that data is "grouped" based on starting and ending tags.

What I want is to group each xml block into one line
So...
<org.m5.api.v1.Response....         >
    <ErrorCount>0</ErrorCount>
    blah...blah...blah..
</org.m5.api.v1.Response>

Becomes
<org.m5.api.v1.Response><ErrorCount>0</ErrorCount>  blah..</org.m5.api.v1.Response>



        Dim list As New List(Of String)

        ' Open file.txt with the Using statement.
        Using r As StreamReader = New StreamReader("C:\temp\Output.txt")
            ' Store contents in this String.
            Dim line As String

            ' Read first line.
            line = r.ReadLine

            ' Loop over each line in file, While list is Not Nothing.
            Do While (Not line Is Nothing)
                ' Add this line to list.
                list.Add(line)
                'Me.ListBox1.Items.Add(line)
                ' Display to console.
                'Console.WriteLine(line)
                ' Read in the next line.
                line = r.ReadLine
            Loop
        End Using

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Larry Brister

ASKER

Perfect. Thanks