【发布时间】:2020-07-09 03:07:42
【问题描述】:
我有一个 SDP 文件,我将其转换为如下字符串:
v=0
o=- 1443716955 1443716955 IN IP4 10.20.130.110
m=video 20000 RTP/AVP 96 // <== this line
c=IN IP4 239.0.1.2/64
a=source-filter: incl IN IP4 239.0.1.2 192.168.0.1
a=rtpmap:96 raw/90000
a=mid:primary
m=video 20000 RTP/AVP 96 // <== this line
c=IN IP4 239.0.1.3/64
a=source-filter: incl IN IP4 239.0.1.3 192.168.0.1
在这一行“m=video 20000 RTP/AVP 96”我想把'20000'改成'4321',我写了下面的代码:
let fileds= inputString .split(/\s+/);
for(const field of fields) {
if(field === "m=video") {
}
if (field === "m=audio") {
var myflag = "au";
}
}
及以上 ode 给我以下结果:
m=video 4321 RTP/AVP 96
m=video 4321 RTP/AVP 96
我只想更改它们并替换为字符串(如新字符串),想象一下我需要如下结果:
v=0
o=- 1443716955 1443716955 IN IP4 10.20.130.110
m=video 4321 RTP/AVP 96 // <== this line
c=IN IP4 239.0.1.2/64
a=source-filter: incl IN IP4 239.0.1.2 192.168.0.1
a=rtpmap:96 raw/90000
a=mid:primary
m=video 4321 RTP/AVP 96 //<== this line
c=IN IP4 239.0.1.3/64
a=source-filter: incl IN IP4 239.0.1.3 192.168.0.1
我是java脚本的新手,我该如何替换它?因为也许我在第 2 行的“m”中有另一个具有不同“m=video”索引的字符串,可能在第 3 行或第 4 行的下一个字符串“m=video”中。
我可以使用'string.startswith('m=video')'吗?在我这个代码的地方用我得到的替换它
EX : m=video 4321 RTP/AVP 96
【问题讨论】:
标签: javascript arrays string replace startswith