Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove last element from url

Tags:

I need to remove the last part of the url from a span..

I have

<span st_url="http://localhost:8888/careers/php-web-developer-2" st_title="PHP Web Developer 2" class="st_facebook_large" displaytext="facebook" st_processed="yes"></span></span> 

And I need to take the st_url and remove the php-web-developer-2 from it so it is just http://localhost:8888/careers/.

But I am not sure how to do that. php-web-developer-2 will not always be that but it won't have any / in it. It will always be a - separated string.

Any Help!!??

like image 699
Steven Avatar asked Jun 04 '12 19:06

Steven


People also ask

How do I remove the last value from a url?

First you need to parse the tag. Next try to extract st_url value which is your url. Then use a loop from the last character of the extracted url and omit them until you see a '/'. This is how you should extract what you want.

How do you get rid of the last part of a url in Python?

rstrip. The string method rstrip removes the characters from the right side of the string that is given to it. So, we can use it to remove the last element of the string.

How do I get the last part of a url response?

The split() method first splits the url into an array of elements separated by the / then pop () method helps us to get the last element of an array (that is our url last segment). Similarly, we can also get the last segment by using the combination of substring() , lastIndexOf() methods.

What is the last portion of url?

There's the name of the website in question, then the Top-Level Domain (TLD). The latter term refers to the .com , . org , . net designation (among others) part of the url at the end of the domain name.


1 Answers

as simple as this:

var to = url.lastIndexOf('/'); to = to == -1 ? url.length : to + 1; url = url.substring(0, to); 
like image 73
www.diwatu.com Avatar answered Oct 08 '22 09:10

www.diwatu.com