JavaScript的substring()方法,
分享于 点击 46241 次 点评:181
JavaScript的substring()方法,
一. substring() 方法用于提取字符串中介于两个指定下标之间的字符
如果参数为一个,则表示开始位置,结束默认最后,如:
var str=“Hello world!”
document.write(str.substring(3))
输出:lo world
二. public String substring(int beginIndex, int endIndex)
第一个int为开始的索引,对应String数字中的开始位置,
第二个是截止的索引位置(不包括它),对应String中的结束位置
1、取得的字符串长度为:endIndex - beginIndex;
2、从beginIndex开始取,到endIndex结束,索引从0开始,其中不包括endIndex位置的字符
如:
var str=“Hello world!”
document.write(str.substring(3,7))
输出:
lo w
相关文章
- 暂无相关文章
用户点评