Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何对url进行字符串操作和解析_C#_Asp.net_String Comparison - Fatal编程技术网

C# 如何对url进行字符串操作和解析

C# 如何对url进行字符串操作和解析,c#,asp.net,string-comparison,C#,Asp.net,String Comparison,假设我有一个随机URL列表,这些URL是完全格式化的: http://www.example1.com, http://example2.biz, http://www.example3.co.uk 我的url值来自一个文本框和一个urlSufix的下拉列表 因此,用户正在插入url: 标签:www.,文本框[仅插入域名],DDL[.com、.biz、.co.uk、.net、.info] 假设用户输入了“example3”并选择了sufix.biz 所以我的值是“example3.biz”

假设我有一个随机URL列表,这些URL是完全格式化的:

http://www.example1.com, 
http://example2.biz, 
http://www.example3.co.uk
我的url值来自一个文本框和一个urlSufix的下拉列表

因此,用户正在插入url:

标签:
www.
,文本框
[仅插入域名]
,DDL
[.com、.biz、.co.uk、.net、.info]

假设用户输入了“example3”并选择了sufix.biz

所以我的值是
“example3.biz”

我需要一个方法来比较列表中的URL和用户输入

我想我会把绳子分开(“.”)

所以选择是 对于前缀:

www.example
或者只是

example
为苏菲克斯

example.com \ biz \net \info ->  (2 parts)
example.co.uk \org.uk (3 parts) 
所以有很多选择

可以是带有aray的前缀,它有2个元素

www.example
sufix和3 example.co.uk

这样检查很复杂

我用comparisson techniq将URL按点拆分时选择了错误的路径吗

我会告诉你我是如何开始的,当我发现太多的时候我就停止了

这还没有涵盖所有选项,而且已经太复杂了

if (ListArr[0] != "www")
{ // it means no www so

      compare userArr[0] to ListArr[0] // to check domainMatch

      // and for suffix of domain 
      var DDLValueArr = DDLValue.split('.');
      if(DDLValueArr.length > 1) means it is co.uk or org.uk etc'
      {
             compare DDLValueArr[0] to ListArr[1]   
      }
}

else 
compare userArr[0] to ListArr[1] cause the url in the List starts with "www"
什么是比较用户输入和url列表的好方法

您可以使用和来创建uri,例如:

List<Uri> uris = new List<Uri>(){ 
   new Uri("http://www.example1.com"), 
   new Uri("https://www.example2.biz"), 
   new Uri("http://www.example3.co.uk")
};

string input = "www.example2.biz";
Uri newUri = new UriBuilder(input).Uri;
if (uris.Any(u=> u.Host == newUri.Host))
{
    MessageBox.Show("Already in the list");
}
List uris=new List(){
新Uri(“http://www.example1.com"), 
新Uri(“https://www.example2.biz"), 
新Uri(“http://www.example3.co.uk")
};
字符串输入=“www.example2.biz”;
urinewuri=newuribuilder(输入).Uri;
if(uris.Any(u=>u.Host==newUri.Host))
{
MessageBox.Show(“已在列表中”);
}

请注意,如果uri未指定方案,则
UriBuilder
默认为“http:”。

比较是什么意思?您是否正在尝试查看用户是否选择了列表中已存在的URI?@keyboard p是的。您是否考虑将
www.example.com
example.com
相同?如果是这样的话,你每次都可以忽略
www
。对不起,我忘了这可能是因为该域将有
http://sub.domainName....
还有
httpS://sub.domainName….
etc'绝对路径只是TLD后面的值,对吗?对于所有这些,不是都是“/”吗?@Gray:你说得对,把它改成与
主机
共同比较。如果他想包括端口,他必须使用
Authoprity
。干杯!!这看起来很棒。如果存在的话,我真的应该寻找那种类型的课程。。但是,测试的完整实现仍然比其他任何东西都好!要清楚的是,主机只是“www.example3.co.uk”和“www.example1.com”。因此,“subdomain.example.com”将不同于“www.example.com”。虽然“http/https/ftp/etc”,但它适用于协议。@Gray昨天忘了感谢您在这里的帮助!谢谢,伙计