• 将查询字符串解析转换为泛型List的名值集合.


    ///<summary>
    ///将查询字符串解析转换为泛型List的名值集合.
    ///</summary>
    ///<param name="queryString">查询字符串的值</param>
    ///<returns>结果</returns>
    public static List<NameValueCollection> GetMultipleRecords(string records)
    {
    List<NameValueCollection> result = new List<NameValueCollection>();
    if (string.IsNullOrEmpty(records))
    {
    return result;
    }

    string[] items = records.Split('|');
    if (items == null || items.Length == 0)
    {
    return result;
    }

    foreach (string item in items)
    {
    NameValueCollection current = GetQueryString(item);
    if (current.Count == 0)
    {
    continue;
    }

    result.Add(current);
    }

    return result;
    }

    ///<summary>
    ///将查询字符串解析转换为名值集合.
    ///</summary>
    ///<param name="queryString">查询字符串的值</param>
    ///<returns>结果</returns>
    public static NameValueCollection GetQueryString(string queryString)
    {
    NameValueCollection result = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
    if (string.IsNullOrEmpty(queryString))
    {
    return result;
    }

    string key = string.Empty;
    string value = string.Empty;
    string[] items = queryString.Split('&');
    foreach (string item in items)
    {
    if (!string.IsNullOrEmpty(item))
    {
    string[] fields = item.Split('=');
    if (fields != null && fields.Length == 2)
    {
    key = fields[0].Trim();
    value = fields[1].Trim();

    if (string.IsNullOrEmpty(key))
    {
    continue;
    }

    result[key] = value;
    }
    }
    }

    return result;
    }

  • 相关阅读:
    poj 2349 Arctic Network
    hdu 1596 find the safest road
    Codeforces 768B. Code For 1
    Codeforces 448C. Painting Fence
    Problem D. Ice Cream Tower(2016 China-Final)
    poj 2785 4 Values whose Sum is 0
    Codeforces 797C. Minimal string
    Codeforces 264A. Escape from Stones
    乌龟棋(noip2010)
    noip2018模拟题(类背包+贪心)
  • 原文地址:https://www.cnblogs.com/jameshappy/p/3519453.html
Copyright © 2020-2023  润新知