zoukankan      html  css  js  c++  java
  • substring() slice() substr()的区别联系

    例如:var str='q1207526854'

    str.substring(form,to):从字符串里截取下标为form到下标为to的字符串(不包括to对应的字符)alert(str.substring(2,6))   // 2075
      当form>to时,substring会把较小的参数作为第一参数     alert(str.substring(6,2))   //2075
      并且当其中某个参数值为负数时,substring会直接将负数转成0。   alert(str.substring(6,-2))   //q12075
     
    str.slice(star,end):从字符串里抽取下标为star到下标为end的字符串(不包括end对应的字符) alert(str.slice(2,6))   //2075
        当star>end时,slice会返回空字符串   alert(str.slice(6,2))   // null
        并且当其中某个参数值为负数时,slice会将此参数与字符串长度相加的结果作为参数 alert(str.slice(6,-2))   // 268
        且slice可以对数组操作。
     
     
    str.substr(star,length):从下标为star的字符串开始,截取长度为length的一个子字符串  alert(str.substr(2,6))   // 207526
       当star为负数时,substr会将此参数与字符串长度相加的结果作为参数   alert(str.substr(-6,2))   // 75
       当end为负数时,返回空字符串。 alert(str.substr(6,-2))   // null 
  • 相关阅读:
    eclipse/intellij idea 查看java源码和注释
    理解线程池,看这篇足够了-转
    乐观锁的幂等性方案
    springboot2.0以后的junit
    详解 Java 中的三种代理模式
    MYSQL慢查询配置
    MySQL 数据库性能优化之SQL优化【转】
    SQL中EXPLAIN命令详解---(转)
    spring的面试
    sql joins 7
  • 原文地址:https://www.cnblogs.com/jsingleegg/p/4959256.html
Copyright © 2011-2022 走看看