lava-oushudb-dt-sql-parser/utils/index.js
2018-07-02 18:01:01 +08:00

24 lines
602 B
JavaScript

function replaceStrFormIndexArr(str, replaceStr, indexArr) {
let arr = [];
let result = "";
let index = 0;
if (!indexArr || indexArr.length < 1) {
return str;
}
for (let i = 0; i < indexArr.length; i++) {
let indexItem = indexArr[i];
let begin = indexItem.begin;
result = result + str.substring(index, begin) + replaceStr;
index = indexItem.end + 1;
if (i == indexArr.length - 1) {
result = result + str.substring(index);
}
}
return result;
}
exports.replaceStrFormIndexArr=replaceStrFormIndexArr;