把dictionary所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
作者:互联网
/// <summary> /// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode /// </summary> /// <param name="dicArray">需要拼接的数组</param> /// <param name="code">字符编码</param> /// <returns>拼接完成以后的字符串</returns> public static string CreateLinkStringUrlencode(Dictionary<string, string> dicArray, Encoding code = null) { code = code ?? Encoding.UTF8; StringBuilder prestr = new StringBuilder(); foreach (KeyValuePair<string, string> temp in dicArray) { prestr.Append(temp.Key + "=" + HttpUtility.UrlEncode(temp.Value ?? "null", code) + "&"); } //去掉最後一個&字符 int nLen = prestr.Length; prestr.Remove(nLen - 1, 1); return prestr.ToString(); }
标签:字符,code,dictionary,temp,拼接,prestr,参数值 来源: https://www.cnblogs.com/nayilvyangguang/p/13329773.html