<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var str = '你好,前端小灰狼'
//输出一次
console.log(str)
var res = str.charAt(3) // 按照索引获取字符串
console.log(res)
var str2 = 'HELLO LITLE GRA WOLF'
console.log(str2)
var res2 = str2.toLowerCase()
console.log('转换成小写 ' + res2)
var str3 = 'hello'
console.log(str3)
var res3 = str3.toUpperCase()
console.log('转换成大写 '+res3)
var str4 = '你好,前端小灰狼'
console.log(str4)
var res4 = str.replace('前端','帅气')
console.log('前面 替换成 后面 :'+res4)
var str5 = ' 去除空格 '
console.log(str5)
var res5 = str.trim()
console.log(res5)
var str6 = '2070-3-22'
console.log(str6)
var res6 = str.split('-')
console.log('安 - 分割 '+res6)
var str7= '你好, 前端小灰狼'
// 0 1 2 3 4 5 6 7
console.log(str7)
var res8 = str.substr(1,6) //输出 : 好,前端小灰 (索引从0开始 0到6 )
console.log(res8)
var res9= str.substring(1,6)
console.log(res9) // 输出 :好,前端小 (索引从0开始 不包含 6)
var res10 = str.slice(1,6)
console.log(re3) //输出 : 好,前端小 (索引从1开始)
</script>
</body>
</html>
|