我有一个这样的字符串:http://igrigc.com/business/spoint/Story/Secure-444
我希望使用JavaScript检索2'/'之间的文本“business”。有人可以帮我解决这个问题吗?感谢。
答案 0 :(得分:2)
正如VisioN所说,您可以使用String.prototype.split()
将其拆分。这会根据传递的参数将字符串拆分为数组。它将字符串拆分成任何找到字符串的部分。
在这里,我们可以使用该方法根据/
将链接拆分为不同的部分,以转到business
目录。
var str = "http://igrigc.com/business/spoint/Story/Secure-444";
var parts = str.split("/") //["http:", "", "igrigc.com", "business", "spoint", "Story", "Secure-444"]
console.log(parts[3]); //"business"