首页 > 代码库 > 常用笔记: JS实现VBS当中的Replace

常用笔记: JS实现VBS当中的Replace

<script> //JS实现VBS当中的Replace,替换全部.方法名大写,区别于原方法,与VBS相类似.isIgnore String.prototype.Replace = function(oldValue,newValue,isIgnore)  {      var reg = new RegExp(oldValue,(isIgnore ? ‘i‘ : ‘‘) + "g");      return this.replace(reg, newValue);   } </script>

 


 调用方式:

 

<script>  var str1 = ‘ABCABcAbcaBCaBcabCabc‘.Replace(‘abc‘,‘ABC‘); // ABCABcAbcaBCaBcabCABC  var str2 = ‘ABCABcAbcaBCaBcabCabc‘.Replace(‘abc‘,‘ABC‘,true); // ABCABCABCABCABCABCABC </script>

 

常用笔记: JS实现VBS当中的Replace