Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Parsing some String

Posted on 2005-03-02
5
Medium Priority
?
625 Views
Last Modified: 2008-02-01
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>
0
Comment
Question by:AlexPonnath
  • 3
5 Comments
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13441123
is the delimiter always a line break or ,

I see between CName Response and Presentation there is a ,
0
 

Author Comment

by:AlexPonnath
ID: 13441157
the delimiter for lines is always a line break..
the "," only seperates the 2 Field/valuepairs on the same line
0
 
LVL 12

Accepted Solution

by:
S-Twilley earned 2000 total points
ID: 13441325
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
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13441356
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13441894
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

578 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