字符串操作

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符串操作</title>
</head>
<body>

    <script type="text/javascript">
    //声明字符串 
    var str = '@ilove@You@';//

    //获取字符串的长度
    var len = str.length;

    // /常用的方法
    var res = str.trim('@');

    //获取指定索引的字符  $str[]  $str{}
    var res = str.charAt(4);//char字符  at 在...地方

    //strpos
    var res = str.indexOf('o');

    //strrpos
    var res = str.lastIndexOf('o');

    //连接字符串  +  想起arguments
    var res = str.concat('verymuch',' and you???');

    //截取字符串
    var res = str.slice(2, 7);
    var res = str.substring(2, 7);

    //字符串拆分
    var res = str.split('@');
    // console.log(res);

    //截取字符串
    var res = str.substr(2, 4);

    //大写转换
    var res = str.toUpperCase();

    //小写转换
    var res = str.toLowerCase();

    //字符串替换
    var res = str.replace('love','like');

    //
    

    </script>
</body>
</html>
原文地址:https://www.cnblogs.com/xujing6/p/6369836.html