1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body> </html> <script type="text/javascript"> var str1 = "abc哈哈呵呵123你好"; var s1 = str1.substr(3, 4); console.log(s1); var index = str1.indexOf("呵"); console.log(index); var s2 = str1.replace("哈哈", " hello"); console.log(s2); var str2 = " a b c "; var s3 = str2.trim(); console.log(str2); console.log(s3); var str3 = "哈,呵呵,你好,哎呀,吃饭啦"; var arr = str3.split(","); console.log(arr); str3 = "哈 呵呵 ac sn"; console.log(str3.split(" ")); str3 = "你好,呵呵 哈哈 abc,bvc"; console.log(str3.split(/ |,/)); str3 = "abcdfhg,哈哈 呵呵"; console.log(str3.split("")); </script>
|