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;
    }

  • 相关阅读:
    TCP通信 小例子
    Socket的简单使用
    Redis练习
    资料
    Redis封装帮助类
    使用Redis的基本操作
    Redis配置主从
    Redis基本设置
    clientHeight ,offsetHeight,style.height,scrollHeight的区别与联系
    服务器操作之如何绑定网站
  • 原文地址:https://www.cnblogs.com/jameshappy/p/3519453.html
Copyright © 2011-2022 走看看