parsing file

Posted on 2004-11-04
Last Modified: 2010-04-23
I have a file that looks like
 ISA*3495*00*  *00* 68393*78*~GS*5930*MANNOR*45*56~
I want to use two splits to seperate the segment and the element seperators so that my file looks like this
ISA 3495 00   00 68393
GS 5930 MANNOR 45 56

On two seperate lines like this.  Can anyone give me an example of how to write this code?

Question by:lindapat
    LVL 19

    Accepted Solution

    You must be Reading the file line by line
    So lets assume you have one line in a variable StrLine


    StrLine=StrLine.Replace("*"," ")
    'It seems in the result that you want there's a space for * but only two spaces between 00 and 00, that means the original space is lost better use

    StrLine=StrLine.Replace(" ","") 'Remove all spaces
    StrLine=StrLine.Replace("*"," ")'Convert * to spaces


    Dim StrArr() as String

    'Now StrArr contains all the Lines

    The complete code will look like

    Dim StrLine As String = "ISA*3495*00*  *00* 68393*78*~GS*5930*MANNOR*45*56~"
    'Read from File in the above line
            Dim StrArr() As String
            Dim i As Integer
            StrLine = StrLine.Replace(" ", "") 'Remove all spaces
            StrLine = StrLine.Replace("*", " ") 'Convert * to spaces
            StrArr = StrLine.Split("~")
            For i = 0 To UBound(StrArr)
                MsgBox(StrArr(i)) 'You'd probably like to store it in a new file??


    Author Comment

    thank you very much

    Author Comment

    Thank you  very much.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video discusses moving either the default database or any database to a new volume.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    729 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

    17 Experts available now in Live!

    Get 1:1 Help Now