本文介绍了如何在 WP7 中拆分 URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
WebBrowser 控件中是否有访问查询参数的方法,还是我们必须手动拆分字符串?例如:
Is there a method for accesing Query parameters in the WebBrowser control or do we have to manually break apart the string? For example:
www.mysite?paramter=12345我只需要访问参数的值.我知道在使用 xaml 页面时,我们有 QueryString 属性.是否有类似的处理网页的方法?
I simply need to access the value of parameter. I know when working with xaml pages we have the have the QueryString property. Is there something similar for working with web pages?
推荐答案我不记得我从哪里得到的,可能是这样.
I can't remember where I got this, possibly SO.
public static class UriExtensions { private static readonly Regex QueryStringRegex = new Regex(@"[\?&](?<name>[^&=]+)=(?<value>[^&=]+)"); public static IEnumerable<KeyValuePair<string, string>> ParseQueryString(this Uri uri) { if (uri == null) throw new ArgumentException("uri"); var matches = QueryStringRegex.Matches(uri.OriginalString); for (var i = 0; i < matches.Count; i++) { var match = matches[i]; yield return new KeyValuePair<string, string>(match.Groups["name"].Value, match.Groups["value"].Value); } } }更多推荐
如何在 WP7 中拆分 URI?
发布评论