2010-08-13 30 views
2

我使用的是authorize.net AIM,它們提供的示例代碼打印出響應值的有序列表。在客戶可以看到所有這些信息的屏幕上,不是打印出有序列表,而是如何設置一個開關來訪問數組中的某些索引,並根據爲特定數組索引返回的文本做些事情?製作一個開關,用於處理數組中的項目

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

變化response_array到string[]類型:

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

在C#中,你可以在一個字符串轉換:

switch (response_array[0]) 
{ 
    case "foo": 
     // do something... 
     break; 
    case "bar": 
     // do something else... 
     break; 
    default: 
     // Error? 
     break; 
} 
+0

完美,正是我一直在尋找。 – 2010-08-14 23:44:39

相關問題