我想返回 wav 文件所在的最后一个文件夹:
所以如果我们有这个 URL:
const dec = "https://langfox.ir/expect/sources/frozen_2019/the_beautiful_forest_version_1/are you enjoying your new frozen layer/1614282551749614446037f2253780f2f.wav";
我们应该准确地返回:
你喜欢你的新冷冻层吗
我可以对 url 进行子字符串化,但我无法正确找到/符号的索引 ...
const dec = "https://langfox.ir/expect/sources/frozen_2019/the_beautiful_forest_version_1/are you enjoying your new frozen layer/1614282551749614446037f2253780f2f.wav"
var mySubString = dec.substring(
dec.lastIndexOf("/") - X, // X is something I can't find out
dec.lastIndexOf("/")
);
console.log(mySubString);
我们如何做到这一点?
最佳答案
将我的评论转换为答案,以便 future 的访问者可以轻松找到解决方案。
你可以像这样split + splice
操作:
const dec = "https://langfox.ir/expect/sources/frozen_2019/the_beautiful_forest_version_1/are you enjoying your new frozen layer/1614282551749614446037f2253780f2f.wav";
var p = dec.split('/').slice(-2)[0];
console.log(p);
//=> are you enjoying your new frozen layer
关于javascript - 返回给定 URL 中音频文件的最后一个文件夹名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66375952/