Read key/value pairs in HttpWebResponse

I want to read a string that looks exactly like this:

VPSProtocol=2.22
Status=OK
StatusDetail=0000 : The Authorisation was Successful.
VPSTxId={BBF09A43-913E-14E3-B41B-E5464B6FF8A9}
SecurityKey=EH8VFZUSH9
TxAuthNo=4979698
AVSCV2=SECURITY CODE MATCH ONLY
AddressResult=NOTMATCHED
PostCodeResult=NOTMATCHED
CV2Result=MATCHED
CAVV=AAABARR5kwAAAAAAAAAAAAAAAAA=
3DSecureStatus=OK

...into a Dictionary preferably. I've tried splitting on the vbcrlf (there is one on every line I can assure you) and on the '=', but can't quite get it to behave correctly often getting out of bounds errors. Anyone got some fantastic ideas on how to solve this?

Help, as always, appreciated.

Answers


You could use a StringReader:

Dim dic = New Dictionary(Of String, String)
Using reader = New StringReader(someString)
    Dim line As String = reader.ReadLine()
    While line <> Nothing
        Dim tokens = line.Split("=")
        If tokens.Length < 2 Then
            Continue While
        End If
        dic.Add(tokens(0), tokens(1))
        line = reader.ReadLine()
    End While
End Using

Need Your Help

An iterator adaptor implementing an SQL-like RIGHT OUTER JOIN using a HashMap

iterator rust

I'm trying to extend bluss's rust-itertools with SQL-like join iterators. I encountered a particular problem with RIGHT OUTER JOIN using a hash join strategy (the strategy itself is actually very

How does a CA decide if entity is trustworthy

java security encryption certificate x509

I am currently programming a Certification Authority for a uni class, I am currently struggling with the concept of creating the certificates.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.