批量重命名实用程序:重命名音轨

问题描述 投票:0回答:1

所以我想重新命名多个音轨

来自

10。黑洞太阳_Soundgarden

10。声音花园_黑洞太阳


我发现了这个:

var char2find = "_";
var index = name.lastIndexOf(char2find);
newName = name.substr(index+1) + char2find + name.substr(0,index);

但这会将乐队名称移到数字前面,如下所示:

声音花园_10。黑洞太阳

我尝试对其进行调整以满足我的需求,但效果不佳。有人可以让我知道我做错了什么吗?非常感谢任何帮助。

javascript substr
1个回答
0
投票

使用split方法拆分Name和sequence number

const name = "10. Black Hole Sun_Soundgarden"
const char2find = "_";
const [i, n] = name.split(". ")
const index = n.lastIndexOf(char2find);
const newName = n.substr(index + 1) + char2find + n.substr(0, index);

const result = i + ". " + newName
console.log(result) // 10. Soundgarden_Black Hole Sun
© www.soinside.com 2019 - 2024. All rights reserved.