gpt4 book ai didi

c# - 如何分解 WP7 中的 URI?

转载 作者:行者123 更新时间:2023-11-30 14:00:22 25 4
gpt4 key购买 nike

在 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);
}
}
}

关于c# - 如何分解 WP7 中的 URI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10936266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com