views:

61

answers:

1

I'm using authorize.net AIM, the sample code they provide prints an ordered list of the response values. Rather than print out an ordered list to the screen where the customer would see all this information, how do I set up a switch to access certain indexs of the array and do something based on the text returned for the particular array index?

String post_response;
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))
{
    post_response = responseStream.ReadToEnd();
    responseStream.Close();
}

// the response string is broken into an array
// The split character specified here must match the delimiting character specified above
Array response_array = post_response.Split('|');

// the results are output to the screen in the form of an html numbered list.
resultSpan.InnerHtml += "<OL> \n";
foreach (string value in response_array)
{
    resultSpan.InnerHtml += "<LI>" + value + "&nbsp;</LI> \n";
}
resultSpan.InnerHtml += "</OL> \n";
+4  A: 

Change the type of response_array to string[]:

string[] response_array = post_response.Split('|');

In C# you can switch on a string:

switch (response_array[0])
{
    case "foo":
        // do something...
        break;
    case "bar":
        // do something else...
        break;
    default:
        // Error?
        break;
}
Mark Byers
Perfect, exactly what I was looking for.
nick