开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜