我试图替换字符串中的一些十六进制代码。这是我的字符串:
"https://r4---sn-p5qlsnsy.googlevideo.com/videoplayback?sparams=clen%2Cdur%252Cei%252Cgir%252Cid%252Cinitcwndbps%252Cip%252Cipbits%252Citag%252Clmt%252Cmime%252Cmm%252Cmn%252Cms%252Cmv%252Cpl%252Crequiressl%252Csource%252Cexpire%26ipbits=0%26requiressl=yes%26signature=6F1247213581BAB17D93BEB155E51A87FE273272.98CCB77419DD3369BFBD4024E045FA02CF37EA53%26mime=video%252F3gpp%26initcwndbps%3D3172500%26c%3DWEB%26pl%3D21%26ei%3D0njrWqGQKYiF8wSJoaiABw%26clen%3D5078833%26itag%3D36%26gir%3Dyes%26mt%3D1525381200%26mn%3Dsn-p5qlsnsy%252Csn-vgqs7ney%26mm%3D31%252C26%26id%3Do-AMFAbDddd4Dd83KwkSZ0Q0BRT-lADdhBUSTA-ZwdlKhg%26dur%3D185.341%26lmt%3D1511566272128708%26ip%3D54.81.171.42%26key%3Dyt6%26fexp%3D23724337%26mv%3Dm%26expire%3D1525402930%26source%3Dyoutube%26fvip%3D4%26ms%3Dau%252Conr&type=video/3gpp;+codecs%3D=mp4v.20.3%2C+mp4a.40.2%22,quality=small&itag=17%"
我试图替换"%3D"使用" =",但它无效。
b = "https://r4---sn-p5qlsnsy.googlevideo.com/videoplayback?sparams=clen%2Cdur%252Cei%252Cgir%252Cid%252Cinitcwndbps%252Cip%252Cipbits%252Citag%252Clmt%252Cmime%252Cmm%252Cmn%252Cms%252Cmv%252Cpl%252Crequiressl%252Csource%252Cexpire%26ipbits=0%26requiressl=yes%26signature=6F1247213581BAB17D93BEB155E51A87FE273272.98CCB77419DD3369BFBD4024E045FA02CF37EA53%26mime=video%252F3gpp%26initcwndbps%3D3172500%26c%3DWEB%26pl%3D21%26ei%3D0njrWqGQKYiF8wSJoaiABw%26clen%3D5078833%26itag%3D36%26gir%3Dyes%26mt%3D1525381200%26mn%3Dsn-p5qlsnsy%252Csn-vgqs7ney%26mm%3D31%252C26%26id%3Do-AMFAbDddd4Dd83KwkSZ0Q0BRT-lADdhBUSTA-ZwdlKhg%26dur%3D185.341%26lmt%3D1511566272128708%26ip%3D54.81.171.42%26key%3Dyt6%26fexp%3D23724337%26mv%3Dm%26expire%3D1525402930%26source%3Dyoutube%26fvip%3D4%26ms%3Dau%252Conr&type=video/3gpp;+codecs%3D=mp4v.20.3%2C+mp4a.40.2%22,quality=small&itag=17%"
b = b.replace("%3D", "=")
我在Windows 10中使用谷歌浏览器
答案 0 :(得分:1)
使用""
进行字符串初始化,并使用全局替换来替换所有比较器/%3D/g
:
b = "https://r4---sn-p5qlsnsy.googlevideo.com/videoplayback?sparams=clen%2Cdur%252Cei%252Cgir%252Cid%252Cinitcwndbps%252Cip%252Cipbits%252Citag%252Clmt%252Cmime%252Cmm%252Cmn%252Cms%252Cmv%252Cpl%252Crequiressl%252Csource%252Cexpire%26ipbits=0%26requiressl=yes%26signature=6F1247213581BAB17D93BEB155E51A87FE273272.98CCB77419DD3369BFBD4024E045FA02CF37EA53%26mime=video%252F3gpp%26initcwndbps%3D3172500%26c%3DWEB%26pl%3D21%26ei%3D0njrWqGQKYiF8wSJoaiABw%26clen%3D5078833%26itag%3D36%26gir%3Dyes%26mt%3D1525381200%26mn%3Dsn-p5qlsnsy%252Csn-vgqs7ney%26mm%3D31%252C26%26id%3Do-AMFAbDddd4Dd83KwkSZ0Q0BRT-lADdhBUSTA-ZwdlKhg%26dur%3D185.341%26lmt%3D1511566272128708%26ip%3D54.81.171.42%26key%3Dyt6%26fexp%3D23724337%26mv%3Dm%26expire%3D1525402930%26source%3Dyoutube%26fvip%3D4%26ms%3Dau%252Conr&type=video/3gpp;+codecs%3D=mp4v.20.3%2C+mp4a.40.2%22,quality=small&itag=17%";
b = b.replace(/%3D/g, "=");
console.log(b);
答案 1 :(得分:0)
您似乎需要用引号括起您分配给b
的值。
b = "https://r4---sn-p5qlsnsy.googlevideo.com/videoplayback?sparams=clen%2Cdur%252Cei%252Cgir%252Cid%252Cinitcwndbps%252Cip%252Cipbits%252Citag%252Clmt%252Cmime%252Cmm%252Cmn%252Cms%252Cmv%252Cpl%252Crequiressl%252Csource%252Cexpire%26ipbits=0%26requiressl=yes%26signature=6F1247213581BAB17D93BEB155E51A87FE273272.98CCB77419DD3369BFBD4024E045FA02CF37EA53%26mime=video%252F3gpp%26initcwndbps%3D3172500%26c%3DWEB%26pl%3D21%26ei%3D0njrWqGQKYiF8wSJoaiABw%26clen%3D5078833%26itag%3D36%26gir%3Dyes%26mt%3D1525381200%26mn%3Dsn-p5qlsnsy%252Csn-vgqs7ney%26mm%3D31%252C26%26id%3Do-AMFAbDddd4Dd83KwkSZ0Q0BRT-lADdhBUSTA-ZwdlKhg%26dur%3D185.341%26lmt%3D1511566272128708%26ip%3D54.81.171.42%26key%3Dyt6%26fexp%3D23724337%26mv%3Dm%26expire%3D1525402930%26source%3Dyoutube%26fvip%3D4%26ms%3Dau%252Conr&type=video/3gpp;+codecs%3D=mp4v.20.3%2C+mp4a.40.2%22,quality=small&itag=17%";