?
Solved

Group data from text file

Posted on 2013-06-07
2
Medium Priority
?
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

770 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