zoukankan      html  css  js  c++  java
  • javascript的String字符串对象

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>typeof</title>
    </head>
    <body>
    <script>
    //1.typeof只能判断基本数据类型
    //(1)字符串创建方式一
    // var s='hello';
    //(2)字符串创建方式二
    // var s1=new String('hello')
    // alert(s1 instanceof String);//true
    // alert(typeof(s)) ;//string
    // alert(typeof(s1)) ;//object
    // var i=new Number(2);
    // alert(typeof (i));//object
    //用instanceof判断某一个对象的类型
    // alert(i instanceof Number);//true
    //2.javascript的String字符串对象
    // (1)String对象的属性
    // s='hello';
    // alert(s.length)//5
    //(2)遍历字符串
    // for(var i in s){
    // console.log(s[i]);
    // }
    //3.javascript的String字符串对象方法
    //(1)编排方法
    s='hello';
    // document.write(s.italics())//hello <i>
    // document.write(s.bold())// <b>
    // document.write(s.anchor('star'))// <a>
    //(2)大小写转换方法
    // console.log(s.toUpperCase());//HELLO
    // console.log(s.toLowerCase());//hello
    // console.log(s.charAt(4));//o
    // console.log(s.charCodeAt(4));//111
    //(3)查询字符串 match() search()
    // console.log(s.search('l'));//返回的第一个匹配结果的索引值 2(通过字符串取索引)
    // console.log(s.match('l'));//返回数组,里面是所有匹配结果 ["l", index: 2, input: "hello", groups: undefined]
    // console.log(s.match('l')[0]);// l
    // console.log(s.match('l')[1]);//undefined

    // console.log(s.indexOf('o'));//4 从左往右取
    // console.log(s.lastIndexOf(('l')));//3 从右往左取
    //(4)replace方法 concat方法 split方法
    // console.log(s.replace('l','t'));//hetlo
    // console.log(s.split('e'));//["h", "llo"]
    // console.log(s.concat(' world'));//hello world
    //(5)截取字符串
    console.log(s.substr(1,1));//e
    console.log(s.substring(1,3));//el 左取右不取
    console.log(s.slice(1,3));//el
    console.log(s.slice(1,-1));//ell 左取右不取

    </script>

    </body>
    </html>
  • 相关阅读:
    HDFS文件系统上传时序图 PB级文件存储时序图
    HDFS 文件系统流程图。PB级文件存储时序图。
    HBase 1.1.2 优化插入 Region预分配
    InputStream、OutputStream
    StringBuffer_StringBuilder
    java中的字符串
    升级的三个因素
    装饰设计模式
    IO字符流之读写缓冲区(BufferedWriter、BufferedReader)
    IO(FileWriter/FileReader)字符流:文件的写入、续写、读
  • 原文地址:https://www.cnblogs.com/startl/p/12238160.html
Copyright © 2011-2022 走看看