代码之家  ›  专栏  ›  技术社区  ›  The Muffin Man

对数组中的项进行切换

  •  2
  • The Muffin Man  · 技术社区  · 15 年前

    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";
    
    1 回复  |  直到 12 年前
        1
  •  4
  •   Mark Byers    15 年前

    将响应数组的类型更改为 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;
    }