// 处理脱敏的函数,str指的是要处理的字符串,beginLen:从第几位开始,endLen:倒数几位结束(负数)
desensitization(str, beginLen, endLen){
let len = str.length;
let firstStr = str.substr(0, beginLen);
let lastStr = str.substr(endLen);
let middleStr = str.substring(beginLen, len-Math.abs(endLen)).replace(/[sS]/ig, '*');
let tempStr = firstStr+middleStr+lastStr;
return tempStr;
},
例子:desensitization(str, 4, -3)//从第四位开始到倒数第三位脱敏