js去掉字符串的空格回车换行

it2022-05-06  18

//例如下面这个json串,

中间的\n表示换行 var str = "{' retmsg':'success ',\n' trans_date':' 20170906'}";

console.log(str);

//"{' retmsg':'success ', //' trans_date':' 20170906'}"

//去掉空格 str = str.replace(/\ +/g,"");

console.log(str);

//"{'retmsg':'success', //'trans_date':'20170906'}"

//去掉回车换行 str = str.replace(/[\r\n]/g,"");

console.log(str);

//"{'retmsg':'success','trans_date':'20170906'}"

转载于:https://www.cnblogs.com/ydam/p/9209185.html


最新回复(0)