VB.Net string parse

Posted on 2004-11-02
Last Modified: 2012-05-05

I am new at so please excuse me.  Will this code work? If not would you correct it for me? I want to show each element in label I have created on a form.

Private Sub read835()
        Dim isaLine As String
        Dim elementSep, compositeSep, segmentSep As String
        Dim x As Integer
        Dim tmp() As String
        isaLine = "ISA*00*          *00*          *27*00523          *ZZ*M4788          *040414*2351*U*00401*410500028*0*P*:~"
        elementSep = isaLine.Substring(103, 1)

        For x = 0 To isaLine.Length
            tmp = Split(isaLine, "*")

        lblMsg.Text = tmp(x)
Question by:lindapat
    LVL 96

    Accepted Solution

    Are you thinking about strtok?  If so, then you are a little off there:

    tmp = Split(isaLine, "*") will return the ISA, 00, <blank>, 00, <blank>, 27, 00523...  

    You only need to do this one, and then reference the element that you need.

    LVL 27

    Expert Comment

    Hi lindapat,
    You say you want to show each element in the label you have created on a form.
    Sounds like a contradiction to me.
    How can you show multiple elements in one label?

    Otherwise I agree with Bob:
    Take split out of the loop.
    Maybe display the label with the loop.
    Something like:

    tmp = Splig(isaLine,"*")

    For x = 0 to UBound(tmp)

    LVL 7

    Expert Comment

    One of you problems is that you are attempting to show all items in just the one label. THis will have the effect of placing each string into the label in a very quick manner, in which case you will probably not even notice any of them, except the last one which will remain as the label's text. You could iterate through each element of your resultant array and put them in a list box or something, so that it is clear which elements have been split. Otherwise, just use a messagebox. Cheers.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video discusses moving either the default database or any database to a new volume.

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now