![](/img/trans.png)
[英]How to upload large audio file to a django server given a blob url?
[英]Return the last folder name of the audio file in the given URL
我想返回 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";
我们应该准确返回:
你喜欢你的新冷冻层吗
我可以 substring 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);
我们应该怎么做?
将我的评论转换为答案,以便将来的访问者轻松找到该解决方案。
您可以像这样进行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
在最后一个反斜杠之前获取 substring 中反斜杠的索引:
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.substring(0, dec.lastIndexOf("/")).lastIndexOf("/")+1, dec.lastIndexOf("/") ); console.log(mySubString);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.