我正在阅读历史,我希望当我遇到google查询时,我可以提取查询字符串。我没有使用request或httputility,因为我只是在解析一个字符串。然而,当我遇到这样的URL时,我的程序无法正确地解析它:
http://www.google.com.mt/search?client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&channel=s&hl=mt&source=hp&biw=986&bih=663&q=hotmail&meta=&btnG=Fittex+bil-Google
我试图做的是得到q=的索引和&的索引,然后取中间的单词,但在本例中,&的索引将小于q=,它会给出错误。
有什么建议吗?
谢谢你的回答,看起来一切都很好:)附言。我不能使用httputility,不是我不想用。当我添加对system.web的引用时,when实用程序没有包括在内!它只包含在asp.net应用程序中。再次感谢
发布于 2013-05-08 04:15:49
HttpUtility适用于.Net框架。然而,该类不适用于WinRT应用程序。如果你想从Windows Store App的url中获取参数,你需要使用WwwFromUrlDecoder。您可以使用要从中获取参数的查询字符串从这个类创建一个对象,该对象有一个枚举器,并且还支持lambda表达式。
下面是一个例子
var stringUrl = "http://localhost/?name=Jonathan&lastName=Morales";
var decoder = new WwwFormUrlDecoder(stringUrl);
//Using GetFirstByName method
string nameValue = decoder.GetFirstByName("name");
//nameValue has "Jonathan"
//Using Lambda Expressions
var parameter = decoder.FirstOrDefault(p => p.Name.Contains("last")); //IWwwFormUrlDecoderEntry variable type
string parameterName = parameter.Name; //lastName
string parameterValue = parameter.Value; //Morales您还可以查看http://www.dzhang.com/blog/2012/08/21/parsing-uri-query-strings-in-windows-8-metro-style-apps
https://stackoverflow.com/questions/6082664
复制相似问题