比较2个网址的最佳方式 [英] Best way to compare 2 urls
本文介绍了比较2个网址的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想比较 2 个网址.最好的方法是什么?
I want to compare 2 URLs. Whats the best way to do this?
条件:1)它应该排除http方案.2) 'foo.com/a/b' 和 'foo.com/a' 应该匹配.
Conditions: 1) It should exclude the http scheme. 2) 'foo.com/a/b' and 'foo.com/a' should be a match.
推荐答案
您应该使用 Uri.Compare 方法.
这是一个比较具有不同方案的两个 URI 的示例.
Here is an example to compare two URI's with different schemes.
public static void Test()
{
Uri uri1 = new Uri("http://www.foo.com/baz?bar=1");
Uri uri2 = new Uri("https://www.foo.com/BAZ?bar=1");
var result = Uri.Compare(uri1, uri2,
UriComponents.Host | UriComponents.PathAndQuery,
UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);
Debug.Assert(result == 0);
}
这篇关于比较2个网址的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文