如何在 WP7 中分解 URI?

2024-04-01

是否有一种方法可以访问 WebBrowser 控件中的查询参数,或者我们是否必须手动分解字符串?例如:

http://www.mysite.com?paramter=12345

我只需要访问参数的值。我知道在使用 xaml 页面时我们有 QueryString 属性。处理网页有类似的东西吗?


我不记得从哪里得到这个,可能是这样。

 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);
            }
        }
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 WP7 中分解 URI? 的相关文章

随机推荐