zoukankan      html  css  js  c++  java
  • JavaScript 基础之String对象(六)

    • 使用位置(索引)可以访问字符串中任何的字符:
      var character=carname[7];
    • 使用长度属性length来计算字符串的长度:
      var txt=“Hello World!”;
      document.write(txt.length);
    • 使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置:
      var str=“Hello world, welcome to the universe.”;
      var n=str.indexOf(“welcome”);
    • match()函数查找字符串中特定的字符,并且找到的话返回这个字符。
      var str=“Hello world!”;
      document.write(str.match(“world”) + “
      ”);
      document.write(str.match(“World”) + “
      ”);
      document.write(str.match(“world!”));
    • replace() 方法在字符串中用某些字符替换另一些字符。
      str=“Please visit Microsoft!”
      var n=str.replace(“Microsoft”,“Runoob”);
      -使用函数 toUpperCase() / toLowerCase()进行字符大小写转换:
      var txt=“Hello World!”; // String
      var txt1=txt.toUpperCase(); // txt1 文本会转换为大写
      var txt2=txt.toLowerCase(); // txt2 文本会转换为小写
    • 使用split()函数转为数组:
      txt=“a,b,c,d,e” // String
      txt.split(","); // 使用逗号分隔
      txt.split(" “); // 使用空格分隔
      txt.split(”|"); // 使用竖线分隔
    • 使用反斜线()插入特殊符号
    • 字符串属性:
      length
      prototype
      constructor
    • 字符串方法:
      charAt()
      charCodeAt()
      concat()
      fromCharCode()
      indexOf()
      lastIndexOf()
      match()
      replace()
      search()
      slice()
      split()
      substr()
      substring()
      toLowerCase()
      toUpperCase()
      valueOf()
  • 相关阅读:
    使用密码记录工具keepass来保存密码
    ADO.NET Entity Framework CodeFirst 如何输出日志(EF 5.0)
    Mono 3.2 测试NPinyin 中文转换拼音代码
    Reactive Extensions(Rx) 学习
    Reactive Extensions介绍
    Mono 3.2 上跑NUnit测试
    RazorEngine 3.3 在Mono 3.2上正常运行
    标准数据源访问库
    .Net 跨平台可移植类库正在进行
    Windows安装和使用zookeeper
  • 原文地址:https://www.cnblogs.com/smileyqp/p/12675399.html
Copyright © 2011-2022 走看看