【发布时间】:2012-07-15 14:04:14
【问题描述】:
得到一些url参数后,我想稍后在我的c#代码中使用它们,但格式略有不同。
“http://example/myexample.aspx?attendees=john.sam&speakers=fred.will.tony.amy.al”
我可以使用以下方法以现有格式将值作为字符串获取: c#代码
public string myattendees()
{
string attendees;
attendees = Request.QueryString["attendees"];
return attendees;
}
public string myspeakers()
{
string speakers;
speakers = Request.QueryString["speakers"];
return speakers;
}
myattendees 返回(以句点分隔,不带引号)
约翰·萨姆
和 myspeakers 返回(以句点分隔,不带引号)
fred.will.tony.amy.al
但我想对其进行转换,以便它返回类似这样的字符串,其中包含逗号分隔和单引号值。
'约翰','山姆'
和
'fred' , 'will' , 'tony' , 'amy' , 'al'
在 c# 中执行此操作的最佳方法是什么?使用 NameValueCollection?
*为清楚细节而编辑问题。 *edit - 修正拼写错误。
【问题讨论】:
-
如果您知道它们总是以点分隔,只需
split将它们放入一个数组中。
标签: c# url parameters request.querystring namevaluecollection