zoukankan      html  css  js  c++  java
  • 提取字符串substring()

    提取字符串substring()

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

    语法:

    stringObject.substring(startPos,stopPos) 

    参数说明:

    注意:

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

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

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

    使用 substring() 从字符串中提取字符串,代码如下:

    <script type="text/javascript">
      var mystr="I love JavaScript";
      document.write(mystr.substring(7));
      document.write(mystr.substring(2,6));
    </script>

    运行结果:

    JavaScript
    love
  • 相关阅读:
    hashlib模块
    logging模块
    Python的富比较方法
    格式化符号说明
    __str__与__repr__区别
    2014-07-18&nbsp;10:25

    2014-07-17&nbsp;17:04
    2014-07-17&nbsp;16:44
    2014-07-16&nbsp;15:54
  • 原文地址:https://www.cnblogs.com/codepen2010/p/6900419.html
Copyright © 2011-2022 走看看