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!!??
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.
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.
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.
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.
as simple as this:
var to = url.lastIndexOf('/'); to = to == -1 ? url.length : to + 1; url = url.substring(0, to);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With