看起来像查询字符串,但不会充当查询字符串
我正在 asp.net 中使用 VB,
基本问题是,我想将字符串中的元素配对,就像 request.QueryString()
对查询字符串中的元素所做的那样网页。
然而,我希望它不是查看当前网页查询字符串的函数,而是查看存储为变量的字符串(即查询字符串的精确形式)。
因此,如果我定义一个字符串,例如:
Dim LooksLikeAQueryString As String = "?category1=answer1&category2=answer2"
我想要一个函数,如果我输入 LooksLikeAQueryString 和“category1”,它会输出“answer1”等。
是否有任何东西已经可以做到这一点,或者我必须构建我自己的功能?如果我必须自己构建,有什么建议吗?
我应该补充一点,在这种情况下,我将无法将字符串附加到 url,然后运行 request.QueryString。
I am working with VB in asp.net,
The basic problem is, I want to pair up the elements in a string, exactly like request.QueryString()
will do to the elements in the query string of the web page.
However instead of the function looking at the current webpage query string I want it to look at a string (that is in the exact form of a query string) stored as a variable.
So if I define a string such as:
Dim LooksLikeAQueryString As String = "?category1=answer1&category2=answer2"
I want a function that if I input LooksLikeAQueryString
and "category1" it outputs "answer1" etc.
Is there anything that can already do this or do I have to build my own function? If I have to build my own, any tips?
I should add that in this case I won't be able to append the string to the url and then run request.QueryString.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 HttpUtility.ParseQueryString 方法 - MSDN 链接
You can use the HttpUtility.ParseQueryString method - MSDN link
ParseQueryString 将为您做这件事 - 类似以下内容:
用法:
ParseQueryString will do it for you - something along these lines:
Usage:
如果你不想依赖
System.Web
,我的想法If you dont want the dependancy of
System.Web
, of the top of my head