Get root url in asp.net regex
I wonder if I can do this code in one regex:
String url = "ftp://url.com.other/asd";
url = Regex.Replace( url, "(https|http|ftp|file)://","");
int index = url.IndexOf("/");
if (index != -1)
{
url = url.Remove(index);
}
//resul开发者_JAVA百科t should be: url.com.other
Thanks.
You should use the Uri
class for this, more specifically the Host
property:
Uri uri = new Uri("ftp://url.com.other/asd");
String hostname = uri.Host;
精彩评论