?
Solved

Parsing some String

Posted on 2005-03-02
5
Medium Priority
?
611 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
[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
  • 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

800 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