备忘:
<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>String</title>
</head>
<body>
<script>
var str="abbdfdsffdsfdsfs";
var str2=" abcdefg ";
var b=str.split('d');
document.write(b);
document.write(' ');
document.write(typeof b); //object
document.write('<br>');
var c=str.slice(1,4);//bbd 不包含截取的最后一个,和substring区别是可以有负值 (数组方法)
document.write(c);
var d=str.slice(-4,-1);//dsf slice(start [, end])
document.write('<br>');
document.write(d);
document.write('<br>');
var e=str.substring(1,4);
document.write('e='+e);//bbd 不包含截取的最后一个 substring(start [, end])
document.write('<br>')
var f=str.substr(1,4);//bbdf 包含截取的最后一个 substr(start [, length])
document.write('f='+f);
document.write('<br>');
var g=str.toUpperCase(); //将字符串转换为大写
document.write(g);
document.write('<br>');
document.write(g.toLowerCase()); //将字符串转换为小写
document.write('<br>');
var h=str.replace(/f/g,'c'); //使用/f/g可以替换所有的f
document.write(h);
document.write('<br>');
var i=str.indexOf('f'); //4查找第一个出现的位置
document.write(i);
document.write('<br>');
var j=str.concat('aaaaaaaaaaaaaaaaaa');//abbdfdsffdsfdsfsaaaaaaaaaaaaaaaaaa
document.write(j);
document.write('<br>');
var k=str[4]; //f
document.write(k);
document.write('<br>');
var l=str.charAt(1);//b charAt() 方法可返回指定位置的字符。
document.write(l);
document.write('<br>');
var m=str.charCodeAt(0); //返回字符的Unicode 编码
document.write(m);
document.write('<br>');
document.write(String.fromCharCode(97,98,99));//将ASCII码转换成字符
document.write('<br>');
var n=str.lastIndexOf('d');//12 查找最后一个出现的位置
document.write(n);
document.write('<br>');
var o=str2.trim();
document.write(o.length);//7 trim() 去除的是首尾空白字符,不光空格.
document.write('<br>');
document.write(str2.length);//16
</script>
</body>
</html>
<img src="https://img-blog.csdn.net/20160930165640484?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />