使用百分比符号(%HH)解码十六进制字符串

时间:2015-10-05 11:23:33

标签: javascript url-encoding

我需要从中更改字符串:

Fast-9%20|%20Speed%20(Something-Cool)

对此:

Fast-9 | Speed (Something-Cool)

我怎么能在NodeJS中做到这一点?

3 个答案:

答案 0 :(得分:4)

参考decodeURIComponent

  

decodeURIComponent()方法解码先前由encodeURIComponent或类似例程创建的统一资源标识符(URI)组件。

var str = 'Fast-9%20|%20Speed%20(Something-Cool)';
alert(decodeURIComponent(str));

答案 1 :(得分:0)

试试这个:

var str = 'Fast-9%20|%20Speed%20(Something-Cool)';
str = str.replace(/%20/g, " ");
alert(str);

答案 2 :(得分:0)

var decoded = decodeURIComponent("Fast-9%20|%20Speed%20(Something-Cool)");