zoukankan      html  css  js  c++  java
  • JS中substring()方法(用于提取字符串中介于两个指定下标之间的字符)

    <!DOCTYPE html>

    <html>

     <head>

    <meta charset="UTF-8">

    <title></title>

    </head>

     <body>

    <script type="text/javascript">

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

    //语法:

    //stringObject.substring(start,stop)

    //参数start:必需。一个非负的整数,规定要提取的字串的第一个字符在stringObject中的位置。

    //参数stop:可选。一个非负的整数,比要提取的字串的最后一个字符在stringObject中的位置多1.

    //如果省略该参数,那么返回的字串会一直到字串的结尾。

    //note:与slice()和substr()方法不同的是,substring()不接受负的参数。

    //1.使用 substring() 从字符串中提取一些字符:

    var str = "Hello world!";

    document.write(str.substring(3) + "<br/>");

    //2.使用 substring() 从字符串中提取一些字符:

    var str = "Hello world!";

    document.write(str.substring(3, 7)+ "<br/>");

    </script>

    </body>

     </html>

  • 相关阅读:
    WinForm 资源文件的使用
    php 常量
    netbean使用技巧
    netbeans 7安装xdebug调试php程序
    eclipse 开发技巧
    asp.net 获取客户机IP地址
    NameValueCollection详解
    Paramics插件编程进程间通讯
    Paramics API编程配置
    windows查询端口占用
  • 原文地址:https://www.cnblogs.com/niuniudashijie/p/5992757.html
Copyright © 2011-2022 走看看