Javascript 将 SRT 脚本的句点更改为逗号
Javascript to change periods to commas for SRT script
我有一个一百多套的srt文件。这是一个例子:
<body>
1
0:00:01.040 --> 0:00:07.680
Hello I'm calling for Brenda Smith.
2
0:00:07.680 --> 0:00:12.880
Thank you for requesting to close
your loan by phone. Is now a good time for you to
3
0:00:12.880 --> 0:00:17.680
access the internet and sign the loan closing
documents with me?
我想使用一些 javascript 来将每个开始行中的句点 (.) 更改为所有带有冒号 (:) 的行中的逗号 (,)。但我不确定该怎么做。
我知道这行不通,但我希望有人能够帮助我更接近解决方案:
function myFunction() {
if(document.body.includes(":"){ // I don't know how to target each beginning line in the srt file
var str = document.body.innerHTML;
var res = str.replace(/\./g, ",");
document.body.innerHTML = res;
}}
如果可以将整个 srt 加载到缓冲区中,像这样的替换是许多可能的解决方案之一 -
var res = str
.replace(/:[0-9][0-9]\./g, (match)=>{
return match
.slice(0, -1)
.concat(',');
});
我有一个一百多套的srt文件。这是一个例子:
<body>
1
0:00:01.040 --> 0:00:07.680
Hello I'm calling for Brenda Smith.
2
0:00:07.680 --> 0:00:12.880
Thank you for requesting to close
your loan by phone. Is now a good time for you to
3
0:00:12.880 --> 0:00:17.680
access the internet and sign the loan closing
documents with me?
我想使用一些 javascript 来将每个开始行中的句点 (.) 更改为所有带有冒号 (:) 的行中的逗号 (,)。但我不确定该怎么做。
我知道这行不通,但我希望有人能够帮助我更接近解决方案:
function myFunction() {
if(document.body.includes(":"){ // I don't know how to target each beginning line in the srt file
var str = document.body.innerHTML;
var res = str.replace(/\./g, ",");
document.body.innerHTML = res;
}}
如果可以将整个 srt 加载到缓冲区中,像这样的替换是许多可能的解决方案之一 -
var res = str
.replace(/:[0-9][0-9]\./g, (match)=>{
return match
.slice(0, -1)
.concat(',');
});