Parsing some String

I have a string like the one below and i would like to parse out the folowing info

Value of CName Response: and Presentation Indicator:

So my first thought is to find index of CName Response: and Presentation Indicator: and extract the
data from beteen the 2 indexes which will get me the CName value. On the Presentation Indicator:
i am not sure how to go about it since the value can have diffrent length and i only know after the value
comes a line break. Any ideas how to extract the value ?

Also, how can i extract only the line which contains "CName Response" in this case it is on line 7
but it could be on 8 or even 6.


2850> tteessttCCNNaammeeQQuueerryy  2125551212
Raw TCAP Component dump:
 0xea 0x17 0xcf 0x01 0x00 0xf2 0x12 0x97
 0x10 0x21 0x49 0x43 0x43 0x49 0x20 0x54
 0x45 0x43 0x48 0x20 0x53 0x55 0x50 0x50
 0x4f
CName Response: Info Response ,  Presentation Indicator: Restricted
2851>
AlexPonnathAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

S-TwilleyCommented:
is the delimiter always a line break or ,

I see between CName Response and Presentation there is a ,
0
AlexPonnathAuthor Commented:
the delimiter for lines is always a line break..
the "," only seperates the 2 Field/valuepairs on the same line
0
S-TwilleyCommented:
Ok... try this

Imports System.Text.RegularExpressions

then within your class

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim regCName As New Regex("CName Response: (?<1>[^,\r\f\n]*)")   'Captures the value up the comma
        Dim matchCName As Match = regCName.Match(TextBox1.Text)

        If matchCName.Success Then
            MsgBox(matchCName.Groups(1).Value())
        End If

        Dim regPresentation As New Regex("Presentation Indicator: (?<1>[^\r\f\n]*)")
        Dim matchPresentation As Match = regPresentation.Match(TextBox1.Text)

        If matchPresentation.Success Then
            MsgBox(matchPresentation.Groups(1).Value())
        End If

    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
S-TwilleyCommented:
The first regular expression searches for "CName Response: " then captures any text after that up until a comma or new line character is found. It tests for that, then msgbox the result if found.

The first regular expression searches for "Presentation Indicator:" then captures any text after that up until a new line character is found. It tests for that, then msgbox the result if found.


Hope this is what you intended
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
If Regexs are greek to you then split the entire string on vbCrLF and iterate through it until you find the string beginning with "CName".  Then split that line into two parts using a comma.  You can the split those two parts with the colon to get the info you need:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim msg As String = _
            "tteessttCCNNaammeeQQuueerryy(2125551212)" & vbCrLf & _
            "Raw TCAP Component dump:" & vbCrLf & _
            "0xea 0x17 0xcf 0x01 0x00 0xf2 0x12 0x97" & vbCrLf & _
            "0x10 0x21 0x49 0x43 0x43 0x49 0x20 0x54" & vbCrLf & _
            "0x45 0x43 0x48 0x20 0x53 0x55 0x50 0x50" & vbCrLf & _
            "0x4f" & vbCrLf & _
            "CName Response: Info Response ,  Presentation Indicator: Restricted" & vbCrLf

        Dim line As String
        Dim lines() As String = Split(msg, vbCrLf)
        Dim part As String
        Dim parts() As String
        Dim values() As String

        Dim CNameResponse As String
        Dim PresentationIndicator As String

        For Each line In lines
            If line.StartsWith("CName Response:") Then
                parts = Split(line, ",")
                For Each part In parts
                    values = Split(part, ":")
                    part = part.Trim
                    If part.StartsWith("CName Response:") Then
                        CNameResponse = values(1).Trim
                    ElseIf part.StartsWith("Presentation Indicator:") Then
                        PresentationIndicator = values(1).Trim
                    End If
                Next
                Exit For
            End If
        Next

        Debug.WriteLine(CNameResponse)
        Debug.WriteLine(PresentationIndicator)
    End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.