string to string collection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a string that is in the format of a url query string, but it is not a
query string.
"RESULT=126&PNREF=V54A0A779FD7&RESPMSG=Under review by Fraud
ice&AUTHCODE=422PNI&AVSADDR=N&AVSZIP=N&IAVS=N&PREFPSMSG=Review"
It's a return from verisign

What is the easiest way to split this up into string collection?
of type stringcollection so that i can get to the value pairs?

there has to be an easy way t odo this
 
is this the best way (or even a good way)
Dim strval As NameValueCollection = New NameValueCollection
Dim rsp() As String
rsp = ResponseOut.Split("&")
Dim s As String
For Each s In rsp
strval.Add(s.Split("=")(0), s.Split("=")(1))
Next
Me.lblResults.Text &= strval.Item("RESULT")
 
WebBuilder,

Almost every day I see something new in this newsgroups. I did not know this
collection exist.

However, what can be wrong with your code when it is working (I did not
check it). In my opinion does it look nice.

Beneath, only to make the code you wrote more compact, not the syntax (2003
and newer)

\\\
Dim strval As New NameValueCollection
Dim rsp() As String = ResponseOut.Split("&")
For Each s as String in rsp
strval.Add(s.Split("=")(0), s.Split("=")(1))
Next
Me.lblResults.Text &= strval.Item("RESULT")
///

I hope this helps someting

Cor
 
thanks!!!!
I discovered this class while trying to find a solution. It's light weight
and will work well for short lists. It's about time i posted something that
was helpful!!
your feed back made my day!
kes
 
Kes,
The only change I would make to your & Cor's code is to only do the
s.Split("=") once:

Dim strval As New System.Collections.Specialized.NameValueCollection
Dim rsp() As String = responseout.Split("&"c)
For Each s As String In rsp
Dim pair() As String = s.Split("="c)
strval.Add(pair(0), pair(1))
Next

Me.lblResults.Text &= strval.Item("RESULT")

Note: "&"c is a char literal, while "&" is a string literal, String.Split
expects a Char parameter. Option Strict On will complain about passing a
String literal to a Char parameter...

Hope this helps
Jay

|I have a string that is in the format of a url query string, but it is not
a
| query string.
| "RESULT=126&PNREF=V54A0A779FD7&RESPMSG=Under review by Fraud
| ice&AUTHCODE=422PNI&AVSADDR=N&AVSZIP=N&IAVS=N&PREFPSMSG=Review"
| It's a return from verisign
|
| What is the easiest way to split this up into string collection?
| of type stringcollection so that i can get to the value pairs?
|
| there has to be an easy way t odo this
| --
| thanks (as always)
| some day i''m gona pay this forum back for all the help i''m getting
| kes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top