作者:zengshiming | 来源:互联网 | 2023-06-12 18:18
创建一个新的项目,选择类库,然后写举例如下代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem
创建一个新的项目,
选择类库,然后写举例如下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace publicfunction
{
public class PathIsUrl
{
public static bool IsUrl(string url)
{
return Regex.IsMatch(url, @"^(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&%_\./-~-]*)?$", RegexOptions.IgnoreCase);
}
public static bool SuffixIsMatch(string url)
{
string[] suffixs = new string[] {"gif","GIF","jpg","JPG","png","PNG","ico","ICO","css","CSS","sit","SIT","eps","EPS","wmf","WMF",
"zip", "ZIP","ppt","PPT","mpg","MPG","xls","XLS","gz","GZ","rpm","RPM","tgz","TGZ","mov","MOV","exe","EXE","jpeg","JPEG",
"bmp","BMP","js","JS"};
Uri matchurl = new Uri(url);
string pagename = matchurl.AbsolutePath;
int count = 0;
bool flag = false;
for (int i = pagename.Length - 1; i >= 0; i--)
{
count++;
if (pagename[i] == '.')
{
flag = true;
break;
}
}
if (flag == true)
{
string a = pagename.Substring(pagename.Length - (count - 1));
for (int i = 0; i {
if (a.IndexOf(suffixs[i]) != -1)
{
return false;
}
}
return true;
}
else
{
return true;
}
}
}
}
然后生成项目。便得到dll。
然后就是在测试程序中的引用中调用这个dll,
然后就可以使用了。