Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL String Get Directory

I have a string that contains a URL:

var url = "http://www.domain.com/Shared%20Documents/Test%20Plans/CC-12%20Test%20Plan.doc";

I am trying to get the url of the directory (ie remove the filename and keep the rest.) I realize that this is probably pretty simple but I can't seem to find anything on it.

Desired result:

var url = "http://www.domain.com/Shared%20Documents/Test%20Plans/";
like image 251
BlueBird Avatar asked May 07 '26 06:05

BlueBird


1 Answers

 var resultUrl = url.substring(0, url.lastIndexOf("/") + 1);

Working jsfiddle here

like image 100
Achrome Avatar answered May 08 '26 20:05

Achrome



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!