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
[email protected]

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
  • um, so what is your question? Commented Jun 8, 2013 at 23:15
  • 3
    what exactly do you mean by "dynamic"? Thus far this seems like a very basic string parsing problem -- what have you tried that isn't working for you? Commented Jun 8, 2013 at 23:15
  • Assuming that Googling for "string parsing" doesn't help you, try "regular expression". Commented Jun 8, 2013 at 23:19
  • By dynamic I mean the values that are sent back from my gateway processor. I4V's solution worked and makes perfect sense. I may have been over thinking the whole thing. Commented Jun 9, 2013 at 0:27

1 Answer 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"]);

if it is in a string, then

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] : "");
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.