直接上函数吧 不废话
function replacestring(oldstr,newstr,text) { var exp = new RegExp(oldstr,‘g‘); var c=text.replace(exp,newstr); return c; } var oldstr=‘world‘; var newstr=‘cccc‘; var text=‘Hello world, Hello world‘; var aa= replacestring(oldstr,newstr,text); console.log(aa);
原文地址:https://www.cnblogs.com/baker95935/p/11330879.html
时间: 2024-10-13 21:41:44