zoukankan      html  css  js  c++  java
  • slice、substring、substr的区别

    var a='hello world';
    var b='hello world';
    var c='hello world';
    var A=a.substr(3,1);
    var B=b.substring(3,5);
    var C=c.slice(3,5);
    console.log('a:'+a+'
    '+'b:'+b+'
    '+'c:'+c);
    console.log(A+'
    '+B+'
    '+C);
    
    //输出
    a:hello world
    b:hello world
    c:hello world
    A:l
    B:lo
    C:lo

    结论

    slicesubstringsubstr都是用来截取字符串的函数。返回一个新的字符串。而且都对原字符串没有影响。

    slicesubstring的用法相同,接收两个参数,第一个参数是从第几位开始截取(包含此位),第二个参数是截取到第几位(不包含此位)。

    substr也接受两个参数,第一个参数是从第几位截取(包含此位),第二个参数是截取几位字符串。

  • 相关阅读:
    Pycharm5注册方式
    五、监听共享目录文件
    三、python webservice
    二、Python安装扩展库
    一、Python安装下载
    test
    拖延
    要乐观对待生活
    乞讨者
    不要总是指责和埋怨
  • 原文地址:https://www.cnblogs.com/zhaozhipeng/p/8080750.html
Copyright © 2011-2022 走看看