【uniapp开发】字符串⼯具类StringUtil 替换字符串中的所有 “***” ⼦串
var str='Is this all there is';
var subStr=new RegExp('is','ig');//创建正则表达式对象,不区分⼤⼩写,全局查
var place(subStr,"");//把'is'替换为空字符串
console.log(result); //th all there
var subStr=new RegExp('is','i');//创建正则表达式对象,区分⼤⼩写
var place(subStr,"");//把'is'替换为空字符串
console.log(result); //this all there is
分割字符串为数组
var address= '111;222;333;444'
let addr = address.split(';');
隐藏店铺名称部分⽂字,⾄多隐藏四个字,
//例如:“ 欧莱雅旗舰店” 变为 **雅**店
formatShopName: function(name) {
var str_array = name.split("");
if(str_array.length < 3){
}
else if(str_array.length == 3){
c++string类型name = place(str_array[1],"*");
}
else if(str_array.length > 3){
var index = 0;
for (var i = 1; i < str_array.length; i+=2) {
if(i!=str_array.length-1 && i!=str_array.length-2 && index<4){
name = place(str_array[i],"*");
index ++;
console.log('name=='+name);
}
}
}
return name;
},
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论