- 0133技术站
- 联系QQ:18840023
- QQ交流群
- 微信公众号
substr()方法通过指定的字符数返回从指定位置开始的字符串中的字符。
语法:
string.substr(start[, length]);
参数:
● start:开始提取字符的位置(0到1之间的整数,小于字符串的长度)。
● length:要提取的字符数
返回值:
substr()方法根据给定的参数返回新的子字符串。
例:
var str = "Apples are round, and apples are juicy."; console.log("(1,2): " + str.substr(1,2)); console.log("(-2,2): " + str.substr(-2,2)); console.log("(1): " + str.substr(1)); console.log("(-20, 2): " + str.substr(-20,2)); console.log("(20, 2): " + str.substr(20,2));
输出:
(1,2): pp (-2,2): y. (1): pples are round, and apples are juicy. (-20, 2): nd (20, 2): d
推荐手册