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

  • 相关阅读:
    get ,post接口测试
    jmeter接口测试 day11
    接口笔记,day01
    python 列表、元组 达内笔记
    linux 笔记达内03
    linux 笔记达内02
    linux 笔记达内01
    Linux/Unix系统下常用的命令
    PageObjectModel页面对象模型(03)
    selenium,实现ECShop后台登录模块测试代码(2)
  • 原文地址:https://www.cnblogs.com/jameshappy/p/3519453.html
Copyright © 2011-2022 走看看