字符串相关方法封装

            /**
             *  1.替换字符串中指定内容
             *  s1 被替换字符串
             *  s2 替换字符串
             */
            String.prototype.replaceAll = function (s1, s2) {
                return this.replace(new RegExp(s1, 'gm'), s2)
            }
            let str = 'qweroioioi'
            console.log(str.replaceAll('o', 'i')) // qweriiiiii

猜你喜欢

转载自blog.csdn.net/weixin_47346395/article/details/107864310