- slice方法:slice方法也可以用来提取字符串的子串,语法为:str.slice(start, end)。其中start为子串的起始位置,end为子串的结束位置(不包括该位置的字符)。
- substring方法:substring方法也可以用来提取字符串的子串,语法为:str.substring(start, end)。其中start为子串的起始位置,end为子串的结束位置(不包括该位置的字符)。
- slice方法和substring方法的区别在于当start大于end时,slice方法会返回一个空字符串,而substring方法会自动交换两个参数的位置。
- substr方法:substr方法可以用来提取字符串的子串,语法为:str.substr(start, length)。其中start为子串的起始位置,length为子串的长度。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>