zoukankan      html  css  js  c++  java
  • 将查询字符串解析转换为泛型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;
    }

  • 相关阅读:
    100多个淘宝抢的双11红包怎么用?最多才能累积使用15个
    灵动标签调用友情链接
    台湾短片:《血战古.宁.头》
    discuz_style_default.xml 修改
    discuz门户文章页面模板修改
    ps快捷键
    拍摄好的图片,如何抠图去背景纯白..
    Centos6.5安装rabbmitmq蛋碎
    好用的YUM源
    python_函数的参数
  • 原文地址:https://www.cnblogs.com/jameshappy/p/3519453.html
Copyright © 2011-2022 走看看