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

  • 相关阅读:
    c++ explicit 用法摘抄
    FBX SDK 从2012.1 到 2013.3 变化
    虚幻4 虚拟漫游场景 制作过程
    3DMAX 建立场景 工作流程
    保存路径选择对话框
    MFC 简单输出EXCEL
    快速使用Log4Cpp
    C# 调用 MFC DLL
    VS建立可供外部调用的MFC类DLL,C#调用MFC调用
    面试中被问到 “你对加班的看法” 该如何回答?
  • 原文地址:https://www.cnblogs.com/xiaoxinstart/p/12555349.html
Copyright © 2011-2022 走看看