ES5中字符串常用的方法:
1. 獲取字符串長(zhǎng)度:length
'hello world'.length????// 11
2. 獲取字符串中某位置的字符:charAt()
'hello world'.charAt(1)????// 'e'
3. 獲取字符串中某位置字符的字符編碼:charCodeAt()、fromCharCode()
'hello world'.charCodeAt(1)????// 101
String.fromCharCode(104,101,108,108,111)????// 'hello'
4. 拼接字符串生成新字符串:concat()谣膳、+
'hello'.concat(' world','!')????// 'hello world!''
hello'+' world'+'!'????// 'hello world!'
5. 基于子字符串創(chuàng)建新字符串:slice()
'hello world'.slice(3)????// 'lo world''
hello world'.slice(3,7)????// 'lo w'
6. 獲取字符串中某個(gè)字符的位置:indexOf()
'hello world'.indexOf('o')????// 4
'hello world'.indexOf('0',6)????// 7
7. 基于子字符串返回消除前后空格的新字符串:trim() /IE9+
' hello world? '.trim()????// 'hello world'
8. 字符串大小寫轉(zhuǎn)換:toLowerCase()智亮、toUpperCase()
'HELLO World'.toLowerCase()????// 'hello world''
Hello world'.toUpperCase()????// 'HELLO WORLD'
9. 字符串的模式匹配:match()
'hello world'.match(/wo/)????// ["wo", index: 6, input: "hello world"]
10. 字符串的模式查找:search()
'hello world'.search(/wo/)????// 6
11. 字符串的模式替換:replace()
'hello world'.replace('world','vikeel')????// 'hello vikeel'
12. 字符串的模式分割:split()
'hello world'.split(' ')????// ['hello', 'world']
'hello world'.split(' ',1)????// ['hello']
ES6中字符串的擴(kuò)展(待續(xù)...)