javascript 提取字符串substring()

来源:互联网 发布:矩阵测光模式 编辑:程序博客网 时间:2024/05/16 02:02

提取字符串substring()

substring() 方法用于提取字符串中介于两个指定下标之间的字符。

语法:
stringObject.substring(star,stop)

注意:

  1. 返回的内容是从 start开始(包含start位置的字符)到 stop-1 处的所有字符,其长度为 stop 减start。

  2. 如果参数 start 与 stop 相等,那么该方法返回的就是一个空串(即长度为 0 的字符串)。

  3. 如果 start 比 stop 大,那么该方法在提取子串之前会先交换这两个参数。

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>string对象</title><script type="text/javascript">var mystr="Hello World!"document.write(mystr.substring(6)+ "<br />"); //提取‘World’;document.write(mystr.substring(0,6));         //提取‘Hello’;</script></head><body></body></html>

结果:

World!Hello
0 0
原创粉丝点击