How to remove the last part of a URL after the last slash (/) in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string url = "http://www.website.com/abc/xyz";
        
        url = url.Substring(0, url.LastIndexOf('/'));

        Console.WriteLine(url); 
    }
}



/*
run:

http://www.website.com/abc

*/

 



answered Feb 20, 2020 by avibootz

Related questions

3 answers 823 views
1 answer 248 views
1 answer 199 views
2 answers 268 views
1 answer 156 views
...