zoukankan      html  css  js  c++  java
  • 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()  将字符转成小写

  • 相关阅读:
    ios常用方法
    XMPP
    ios ebooks
    uinavigationcontroller swipe back
    navigationController and ToolBar
    EMC VNX5200/5400存储 新增LUN与Hosts映射操作
    H3C交换机telnet服务认证模式配置
    配置H3C交换机ftp服务
    克隆CentOS 6.9 配置静态IP,重启网络服务时报错"eth0 does not seem to be present"
    BFS解决八数码问题和狼人过河问题
  • 原文地址:https://www.cnblogs.com/xiaoxinstart/p/12555349.html
Copyright © 2011-2022 走看看