0

I am getting a string returned to my application from my gateway processor. The string contents are:

ssl_result=0
ssl_result_message=APPROVAL
ssl_txn_id=9621F9AD-E49E-4003-91BD-5C1B08569959
ssl_approval_code=N54032
ssl_cvv2_response=
ssl_avs_response=
ssl_invoice_number=123-ABC
ssl_amount=5.00
ssl_card_number=00*******0000
ssl_exp_date=0000
ssl_email=test@test.com

The ssl_result_message could be either "APPROVAL" or "DECLINED". I need to be able to parse the string to determine what the message was and if approved, what the ssl_approval_code is. The problem I am having is these values will be dynamic.

4

1 回答 1

4
var dict = File.ReadLines(filename)
           .Select(line=>line.Split(new char[]{'='},StringSplitOptions.RemoveEmptyEntries))
           .ToDictionary(parts=>parts[0], parts=>parts.Length>1 ? parts[1] : "");

 Console.WriteLine(dict["ssl_result_message"]);

如果它在一个字符串中,那么

var dict = text.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
           .Select(line=>line.Split(new char[]{'='},StringSplitOptions.RemoveEmptyEntries))
           .ToDictionary(parts=>parts[0], parts=>parts.Length>1 ? parts[1] : "");
于 2013-06-08T23:19:47.367 回答