-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString.html
More file actions
50 lines (50 loc) · 1.54 KB
/
String.html
File metadata and controls
50 lines (50 loc) · 1.54 KB
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
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>String</title>
</head>
<body>
<script type="text/javascript">
// String
// 1. length 字符串的长度
console.log("asdas".length)
// 2. str.cahrAt(idnex)
//返回下表为index的子字符串
console.log("sadaf".charAt(2))
// 3. str.charCodeAt(index)
// 返回对应下标的字符的ACSCLL码
console.log("sadfa".charCodeAt(2))
// 4. String.formCharCode(97)
// 将acscll码值转换为字符串
// var a = String.formCharCode(88)
// console.log(a)
// 5. str.indexOf('a')
// 查找一个字符串或者字符串中第一次出现的位置
console.log('asd'.indexOf('a'))
// 6. str.lastIndexOf('a')
// 倒序查找一个字符串或者字符串中第一次出现的位置
console.log('afdf'.lastIndexOf('f'))
// 7. str.replace('替换的内容','替换后的内容')
//只能替换第一个
console.log('hello world'.replace('o','a'))
// 8. str.slice(起始下标,结束下表)
//截取字符串 不包括结束下标
console.log('afsaf'.slice(1,3))
// 9. str.substring(起始下标,结束下标)
console.log('adf'.substr(0,2))
// 10. str.split('')
//分割字符串 返回数组
console.log('asda'.split(''))
// 11. str.toLowerCase()
//转化为 小写
// 12. str.toUpperCase()
//转化为大写
// 13. str.trim()
//去掉字符串的空格
// 14. str.concat('a','b','c')
//连接多个字符串
console.log('faf'.concat('1','2'))
</script>
</body>
</html>