<html>
<head>
<title>Javascript Traning</title>
<script>
//查找字符串位置
var str ="123abc";
var n = str.search(/abc/i);
alert(n);
//替换字符串
var str1 ="zz";
var h =str1.replace("zz","bao");
alert(h);
//slice()返回字符串中提取的子字符串
var str2 ="Hello world";
var str3 = str2.slice(1);//返回下标为1之后的字符串
var str4 = str2.slice(1,6);//返回下标为1到6的字符串
//注意此方法如果一正一负,就表示正数从前边开始截取,负数表示截取到从后往前数到第几个字符
alert(str3);
alert(str4);
//substring()把字符串分割成字符串数组,此方法不接受负值的参数
var str5 ="Hello world";
var str6= str5.substring(2);
var str7= str5.substring(2,7);
alert(str6);
alert(str7);
//substr():返回从指定下标开始指定长度的子字符串
var str8 = "Hello world";
var str9= str8.substr(2);
var str10= str8.substr(2,7);
alert(str9);
alert(str10);
//split()把字符串分割成字符串数组
var str11 = "AA BB CC DD";
var str12 = str11.split("");//用""作为分隔符
alert(str12);
//match()返回所有查找的关键字内容的数组
var string = "haha";
var reg =/to/ig;
var str13 = string.match(reg);
alert(str13);
//concat()连接两个或者多个字符串
var string1 = "haha";
var string2 = "Hello world";
var a = string1.concat("",string2);
alert(a);
//repeat()将字符串进行重复
var b = "hello".repeat(3)+"oo";
alert(b);
</script>
</head>
<body>
</body>
</html>
<script>
</script>