我试图对一个字符串执行以下操作:
"/"的最后出现位置;更明确地说,假设我有以下字符串:
var string = "/Roland/index.php"; // Which is a result of window.location.pathname
现在我需要从中提取的是除了实际页面之外的所有内容,比如:
var result = "index.php" // Which is what I need to be returned
当然,这只是一个例子,因为显然我将有不同的页面,但同样的原则适用。
我在想是否有人能帮我解决这个问题。我尝试了下一步行动,但没有成功:
var location = window.location.pathname;
var result = location.substring(location.lastIndexOf["/"]);