stringObject.substr(start,length)
substr() 的参数指定的是子串的开始位置和长度
(如果是负数,那么该参数声明从字符串的尾部开始算起的位置;-1 指最后一个元素,-2 指倒数第二个元素,以此类推)
stringObject.substring(start,stop)
substring() 方法用于提取字符串中介于两个指定下标之间的字符
截取手机号 中间4位*号代替
this.phone.substr(0, 3) + '****' + this.phone.substr(7) //182****47088
this.phone.substr(0, 3) + '****' + this.phone.substr(-4)
截取邮箱
this.email.substr(0, 3) + '******@' + this.email.split('@')[1] //162****@qq.com
截取最后4个字符
var str="Hello world"
document.write(str.substr(-4)) //orld
document.write(str.substr(-5,3)) //wor
字符串截取substring和substr
猜你喜欢
转载自blog.csdn.net/LR13567/article/details/104777909
今日推荐
周排行