I have a string of parameters from a Javascript function call
ITQPopup('100',255,'2932 NTYwNDUwMTA0MDYzMDM);3094 V0FZ','-1909432577',0,0)
As you can see, this is very poorly coded, there are 6 parameters being passed
'100'
255
'2932 NTYwNDUwMTA0MDYzMDM);3094 V0FZ'
'-1909432577'
0
0
I would split the string by "," (comma) but I'm afraid there could be commas in the 3rd parameter. How would one go about splitting this string?
You can accomplish this easily with RegEx. For instance:
Dim input As String = "ITQPopup('100',255,'2932 NTYwNDUwMTA0MDYzMDM);3094 V0FZ','-1909432577',0,0)"
Dim pattern As String = "ITQPopup\('(.*?)',(.*?),'(.*?)','(.*?)',(.*?),(.*?)\)"
Dim m As Match = Regex.Match(input, pattern)
If m.Success Then
Dim param1 As String = m.Groups(1).Value
Dim param2 As String = m.Groups(2).Value
Dim param3 As String = m.Groups(3).Value
Dim param4 As String = m.Groups(4).Value
Dim param5 As String = m.Groups(5).Value
Dim param6 As String = m.Groups(6).Value
End If
You could further improve the pattern, if necessary, to allow white-space between parameters, etc. But that's the simplest working example.
Strip the content of the brackets, wrap in the square brackets and use JSON library to parse it as array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With