/**
* 替换所有,不支持正则
* @param str {String} 文本
* @param part {String} 旧字符字符
* @param newPart {String} 新字符
* @return {String}
* */
export const replaceAllByIndexOf = (str, part, newPart) => {
const arr = []
const count = str.indexOf(part)
if (count === -1) return
for (let i = 0; i <= count; i++) {
arr.push(i)
}
arr.forEach(item => {
str = str.replace(part, newPart)
})
return str
}
网友评论