Reputation: 41
I have a string like this:
+COPS:0,0,"XL",2
or +CSQ: "15",99
How can I get "XL" or "15" from the string.
On the second one, I've tried using replace and remove +CSQ:
and ,99
but I can't do this on the first one.
Upvotes: 2
Views: 1499
Reputation: 92
You could use Regular expressions for that task. For example :
Dim stringtoscan = yourstringhere
Dim expression As New Text.RegularExpressions.Regex(Chr(34) + "(.*?)" + Chr(34))
Dim stringMatches = expression .Matches(stringtoscan)
Upvotes: 0
Reputation: 3058
Same spirit as @Phillip Trelford but avoiding one step splitting on quotes :
Dim line = "+COPS:0,0,""XL"",2"
' Split fields on quotes
Dim fields = line.Split(""""c)
Dim value = fields(1)
One liner function :
Public Function getValue(ByVal from As String) As String
Return from.Split(""""c)(1)
End Function
Upvotes: 0
Reputation: 6543
For the first string use String.Split to split on commas then String.Trim to remove the quotes:
Dim line = "+COPS:0,0,""XL"",2"
' Split fields on comma
Dim fields = line.Split(",")
' Quote literal
Dim quote = """"c
' Use trim to remove quotes
Dim value = fields(2).Trim(quote)
Upvotes: 2