• javascript学习心得之字符串


    1.charAt(index) 输出index位置的字符

     var stringValue = "hello world";
            alert(stringValue.charAt(1));//输出 e

    2.charCodeAt(index) 输出index位置的字符对应的ASCII码

    var stringValue = "hello world";
            alert(stringValue.charCodeAt(1));

    3.concat(str) 连接字符串

      var stringValue = "hello ";
            alert(stringValue.concat("world!"));//输出hello world!

    4.slice(startIndex,endIndex),substring(startIndex,endIndex),substr(startIndex,count) 之间的区别

     var stringValue = "hello world";
            alert(stringValue.slice(3));//输出lo world   ,此时第二个参数没有传值,则默认为字符串的末尾,substr和substring同

            alert(stringValue.slice(3,7)); //输出lo w ,截取从第3位到第6位,同substring

           alert(stringValue.substr(3, 7)); //输出lo worl  从第3位截取7位长度

    5.indexOf(chr,index) 表示返回从index位置开始往后查找字符chr所在的位置

    lastIndexOf(chr,index) 表示返回从index位置开始往前查找字符chr所在的位置

      var stringValue = "hello world";
            alert(stringValue.indexOf('o',6)); //7
            alert(stringValue.lastIndexOf('o',6));//4

    6.trim() 删除前置和后缀所有空格

    7.toUpperCase() 将字符转成大写     toLowerCase()  将字符转成小写

  • 相关阅读:
    习题三 答案
    习题二 答案
    Python开发【第三篇】:Python基本数据类型
    习题四 答案
    第一个python程序-判断登陆用户名和密码是否正确
    BFPRT算法 查找第k小的数
    设计模式----单例模式
    设计模式----原型模式
    非本地跳转
    链接器如何使用静态库解析引用
  • 原文地址:https://www.cnblogs.com/xiaoxinstart/p/12555349.html
Copyright © 2020-2023  润新知