Edw*_*ard 3 c# silverlight windows-phone-7 query-string
是否有一种方法可以在WebBrowser控件中访问Query参数,还是我们必须手动拆分字符串?例如:
http://www.mysite.com?paramter=12345
Run Code Online (Sandbox Code Playgroud)
我只需要访问参数的值.我知道在使用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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1284 次 |
| 最近记录: |