AlexPonnath
asked on
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> tteessttCCNNaammeeQQuueerr yy 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>
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> tteessttCCNNaammeeQQuueerr
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>
ASKER
the delimiter for lines is always a line break..
the "," only seperates the 2 Field/valuepairs on the same line
the "," only seperates the 2 Field/valuepairs on the same line
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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 = _
"tteessttCCNNaammeeQQuueer ryy(212555 1212)" & 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("Presentat ion Indicator:") Then
PresentationIndicator = values(1).Trim
End If
Next
Exit For
End If
Next
Debug.WriteLine(CNameRespo nse)
Debug.WriteLine(Presentati onIndicato r)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim msg As String = _
"tteessttCCNNaammeeQQuueer
"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("Presentat
PresentationIndicator = values(1).Trim
End If
Next
Exit For
End If
Next
Debug.WriteLine(CNameRespo
Debug.WriteLine(Presentati
End Sub
I see between CName Response and Presentation there is a ,