SOURCE

alert('hello yuan')
    // 一、string对象(字符串)
    // 1.字符串对象创建
    // 字符串创建(两种方式)
    //     ① 变量 = “字符串”
    //     ② 字串串对象名称 = new String (字符串)
    var s = "sffghghfd";
    var s1 = new String(' he l lo');
    console.log(s, s1);
    console.log(typeof(s));
    console.log(typeof(s1));
    // ==============
    //1.就这么一个属性
    console.log(s.length);
    //字符串的方法
    console.log(s.toUpperCase())
    console.log(s.toLocaleLowerCase())
    console.log(s1.trim());//去除字符串两边的空格(和python中的strip方法一样,不会去除中间的空格)
    //3.字符串的查询方法
    console.log(s.charAt(3));//获取指定索引位置的字符
    console.log(s.indexOf('f'))//如果有重复的,获取第一个字符的索引,如果没有你要找的字符在字符串中没有就返回-1
    console.log(s.lastIndexOf('f'));  //如果有重复的,获取最后一个字符的索引
    var str = 'weclome to the world of JS!';
    var str1 = str.match('world');//match返回匹配字符串的数组,如果没有匹配则返回null
    var str2 = str.search('world');//search返回匹配字符串从首字符位置开始的索引,如果没有返回-1
    console.log(str1);
    alert(str1);
    console.log(str2);
    alert(str2);
    // =====================
    // 4.子字符串处理方法
    var aaa = 'welcome to the world of JS!';
    console.log(aaa.substr(2, 4));//表示从第二个位置开始截取四个
    console.log(aaa.substring(2, 4));//索引从第二个开始到第四个,注意顾头不顾尾
    //切片操作(和python中的一样,都是顾头不顾尾的)
    console.log(aaa.slice(3, 6));
    console.log(aaa.slice(4));
    console.log(aaa.slice(2, -1));
    console.log(aaa.slice(-3, -1));
    // 字符串替换、
    console.log(aaa.replace('w', 'c'));//字符串替换,只能换一个
    //而在python中全部都能替换
    console.log(aaa.split(' '));
    alert(aaa.split(' '));
    var strArray = aaa.split(' ');
    alert(strArray[2]);
console 命令行工具 X clear

                    
>
console