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()  将字符转成小写

  • 相关阅读:
    linux 装mysql的方法和步骤
    Linux查看系统发行版本
    Spinner
    时间与日期选择器
    Linux目录处理命令
    开发Activity
    js属性操作(2)
    Js的属性操作(1)
    学习java Script的热身作业
    在Windows下搭建Android开发环境
  • 原文地址:https://www.cnblogs.com/xiaoxinstart/p/12555349.html
Copyright © 2011-2022 走看看