Possible Duplicate:
Remove everything after a certain character
what if I have
var shot = www.site.com/ask
and I wanted to remove all character after “/” (including “/”).
So that the result will be
www.site.com
NOTE: shot is dynamically changing value
and this will all done on javascript.
Assuming that you want everything before the
/you could find the index of the character and return the substring before it:If you would want to get the domain from a string including the protocol e.g.
http://www.site.com/askand getwww.site.comthen you would need to include additional logic as the code above would returnhttp:.