Solved

Group data from text file

Posted on 2013-06-07
2
373 Views
Last Modified: 2013-06-07
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

0
Comment
Question by:lrbrister
2 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 500 total points
ID: 39229261
Mmm... if all your end "parent" nodes follow a similar pattern (i.e. all of them contain the "org.m5" string), you can do something like this:

Dim text As String = String.Empty
Do While (Not line Is Nothing)
    text += line
    If line.StartsWith("</org.m5") Then 'Or "</org", if all of your "parent" nodes starts with "<org"
        'Add the line to the list
        Me.ListBox1.Items.Add(text)
        'Clear the text
        text = String.Empty
    End If
    ' Read in the next line.
    line = r.ReadLine
Loop

Open in new window

Hope that helps.
0
 

Author Closing Comment

by:lrbrister
ID: 39229467
Perfect. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

16 Experts available now in Live!

Get 1:1 Help Now