Javascript examples for String:indexOf
Get string between last dash and last dot using string lastIndexOf method
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){// w w w .j a v a 2 s. c o m var test = "http://foo.com/bar/image/abc.jpg"; var i = test.lastIndexOf("/"); var j = test.lastIndexOf("."); var str = test.substring(i + 1, j); document.body.innerHTML += "<p>" + str + "</p>"; } </script> </head> <body> </body> </html>