如何在 WP7 中拆分 URI? [英] How to break apart a URI in WP7?

查看:47
本文介绍了如何在 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:

http://www.mysite.com?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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆