在允许输出C#中的查询字符串操纵 [英] Outputing a manipulated QueryString in c#

查看:120
本文介绍了在允许输出C#中的查询字符串操纵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下code我得到一个不错的格式化字符串:

Using the following code I get a nice formatted string:

Request.QueryString.ToString

给我这样的:&安培;你好=世界和放大器;微软=吸

Gives me something like: &hello=world&microsoft=sucks

但是,当我用这个code到集合克隆到另一个对象(同类型)我得到的类型()回来从ToString()方法来代替。

But when I use this code to clone the collection to another object (of the same type) I get the Type() back from the ToString() method instead.

System.Collections.Specialized.NameValueCollection variables = new System.Collections.Specialized.NameValueCollection(Request.QueryString);
if (!string.IsNullOrEmpty(variables["sid"]))
    variables.Remove("sid");
Response.Write(variables.ToString());

有没有输出整洁方​​式,而不是寻找和手动构建字符串?

Is there a tidier way to output it rather than looking and building the string manually?

推荐答案

您也可以使用反射来的 HttpValueCollection 类解压到你自己的,并用它吧。

You can also use Reflector to extract the HttpValueCollection class into your own, and use it then.

这篇关于在允许输出C#中的查询字符串操纵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆