Dalexan
asked on
Parse tags within string
I have the following string I need to parse and assign the values to textbox's. It looks like the tags are formatted &dataname=. for example I need txtFname.text to = test from the below string.
dim str as string
str = "customer_id=255349&author ized=no&fi rst_name=t est&last_n ame=order& phone=5618 662933&ema il=test%40 test.com&p roduct=50& username=& password=& shipping_a ddress=112 4+apollo+r d&shipping _unit=1124 +apollo+rd &shipping_ city=Melbo urne&shipp ing_state= FL&shippin g_zip=3293 5&shipping _country=U S&billing_ address=11 24+apollo+ rd&billing _unit=1124 +apollo+rd &billing_c ity=Melbou rne&billin g_state=FL &billing_z ip=32935&b illing_cou ntry=US&cc _number=54 5454545454 5454&cc_ex pires=2011 -05-30+23% 3A59%3A59& cc_name_on _account=t est+order& cc_ccid=12 3"
dim str as string
str = "customer_id=255349&author
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Using this requires an array of your textbox names in the same order as they fields (e.g., customer_id) appear in the variable str. You'd then assign the value to the textbox where the Debug.Print statements are. This assumes that the order and number of fields in the input string doesn't change.
Private Sub Form_Load()
Dim str As String
str = "customer_id=255349&author ized=no&fi rst_name=t est&last_n ame=order& phone=5618 662933&ema il=test%40 test.com&p roduct=50& username=& password=& shipping_a ddress=112 4+apollo+r d&shipping _unit=1124 +apollo+rd &shipping_ city=Melbo urne&shipp ing_state= FL&shippin g_zip=3293 5&shipping _country=U S&billing_ address=11 24+apollo+ rd&billing _unit=1124 +apollo+rd &billing_c ity=Melbou rne&billin g_state=FL &billing_z ip=32935&b illing_cou ntry=US&cc _number=54 5454545454 5454&cc_ex pires=2011 -05-30+23% 3A59%3A59& cc_name_on _account=t est+order& cc_ccid=12 3"
Dim parseEquals
parseEquals = Split(str, "&")
Dim ii As Long, jj As Long
Dim KeyValue, parsePluses
For ii = 0 To UBound(parseEquals)
KeyValue = Split(parseEquals(ii), "=")
If InStr(parseEquals(ii), "+") = 0 Then
Debug.Print "Field: " & KeyValue(0) & ", Value: " & KeyValue(1)
Else
parsePluses = Split(KeyValue(1), "+")
For jj = 0 To UBound(parsePluses)
Debug.Print "Field_" & CStr(jj) & ": " & KeyValue(0) & ", Value: " & parsePluses(jj)
Next
End If
Next
End Sub
'''''''''' output from above
Field: customer_id, Value: 255349
Field: authorized, Value: no
Field: first_name, Value: test
Field: last_name, Value: order
Field: phone, Value: 5618662933
Field: email, Value: test%40test.com
Field: product, Value: 50
Field: username, Value:
Field: password, Value:
Field_0: shipping_address, Value: 1124
Field_1: shipping_address, Value: apollo
Field_2: shipping_address, Value: rd
Field_0: shipping_unit, Value: 1124
Field_1: shipping_unit, Value: apollo
Field_2: shipping_unit, Value: rd
Field: shipping_city, Value: Melbourne
Field: shipping_state, Value: FL
Field: shipping_zip, Value: 32935
Field: shipping_country, Value: US
Field_0: billing_address, Value: 1124
Field_1: billing_address, Value: apollo
Field_2: billing_address, Value: rd
Field_0: billing_unit, Value: 1124
Field_1: billing_unit, Value: apollo
Field_2: billing_unit, Value: rd
Field: billing_city, Value: Melbourne
Field: billing_state, Value: FL
Field: billing_zip, Value: 32935
Field: billing_country, Value: US
Field: cc_number, Value: 5454545454545454
Field_0: cc_expires, Value: 2011-05-30
Field_1: cc_expires, Value: 23%3A59%3A59
Field_0: cc_name_on_account, Value: test
Field_1: cc_name_on_account, Value: order
Field: cc_ccid, Value: 123
Private Sub Form_Load()
Dim str As String
str = "customer_id=255349&author
Dim parseEquals
parseEquals = Split(str, "&")
Dim ii As Long, jj As Long
Dim KeyValue, parsePluses
For ii = 0 To UBound(parseEquals)
KeyValue = Split(parseEquals(ii), "=")
If InStr(parseEquals(ii), "+") = 0 Then
Debug.Print "Field: " & KeyValue(0) & ", Value: " & KeyValue(1)
Else
parsePluses = Split(KeyValue(1), "+")
For jj = 0 To UBound(parsePluses)
Debug.Print "Field_" & CStr(jj) & ": " & KeyValue(0) & ", Value: " & parsePluses(jj)
Next
End If
Next
End Sub
'''''''''' output from above
Field: customer_id, Value: 255349
Field: authorized, Value: no
Field: first_name, Value: test
Field: last_name, Value: order
Field: phone, Value: 5618662933
Field: email, Value: test%40test.com
Field: product, Value: 50
Field: username, Value:
Field: password, Value:
Field_0: shipping_address, Value: 1124
Field_1: shipping_address, Value: apollo
Field_2: shipping_address, Value: rd
Field_0: shipping_unit, Value: 1124
Field_1: shipping_unit, Value: apollo
Field_2: shipping_unit, Value: rd
Field: shipping_city, Value: Melbourne
Field: shipping_state, Value: FL
Field: shipping_zip, Value: 32935
Field: shipping_country, Value: US
Field_0: billing_address, Value: 1124
Field_1: billing_address, Value: apollo
Field_2: billing_address, Value: rd
Field_0: billing_unit, Value: 1124
Field_1: billing_unit, Value: apollo
Field_2: billing_unit, Value: rd
Field: billing_city, Value: Melbourne
Field: billing_state, Value: FL
Field: billing_zip, Value: 32935
Field: billing_country, Value: US
Field: cc_number, Value: 5454545454545454
Field_0: cc_expires, Value: 2011-05-30
Field_1: cc_expires, Value: 23%3A59%3A59
Field_0: cc_name_on_account, Value: test
Field_1: cc_name_on_account, Value: order
Field: cc_ccid, Value: 123
ASKER
&cc_name_on_account=test+t
txtFname.text = test
txtMname.text = the
txtLname.text = order