javascript字符串操作

charAt(n)       //返回指定位置(n)的字符 

    var str="abcdefge";
    console.log(str.charAt(3));   //输出d

indexOf(s,n)    //返回从n的位置向后查找s首字出现的位置

    var str="abcdefge";

       console.log(str.indexOf("e",0)); //输出4
       console.log(str.indexOf("e",4)); //输出4
       console.log(str.indexOf("e",5)); //输出7

lastindexof(s,n)  //从n的位置向查找s

     var str="abcdefge";

     console.log(str.lastIndexOf("e",7));    //输出7

toLowerCase()    //将字符串换成小写 

    var strr="ABC";
    console.log(strr.toLowerCase()); //输出abc

toupperCase()      //将字符串转换成大写  

    var ast="abc";
    console.log(ast.toUpperCase()); //输出ABC

slice(a,b)      //提取并返回a b 之间的字符

     var str="abcdefge";

      console.log(str.slice(2,3));        //输出c

split("",n )    //按条件截取字符并转换成字符串(前面的为条件,后面的为几个字符转换)

replace(正则)    //将指定的字符串转换成...

posted @ 2017-09-05 23:17  泉有  阅读(146)  评论(0编辑  收藏  举报