The difference character string taken substr and substring

Both have the same point:

如果只是写一个参数,两者的作用都是一样的:就是截取字符串当前下标以后直到字符串最后的字符串片段。

Except that: the second parameter:

substr(startIndex,lenth): 第二个参数是截取字符串的长度(从起始点截取某个长度的字符串);
substring(startIndex, endIndex): 第二个参数是截取字符串最终的下标 (截取2个位置之间的字符串,‘含头不含尾’);
   let aa='想要回到每个场景,想养一只猫,想要回到每个场景,拨慢每只表';
   let cc=aa.substr(9,14)//第二个参数是截取的长度
   let dd=aa.substring(9,14)//第二哥参数截取字符串最终的下标
   console.log(cc)//想养一只猫,想要回到每个场景
   console.log(dd)//想养一只猫

Guess you like

Origin www.cnblogs.com/foreverLuckyStar/p/12064599.html