1.定义:
var a = "123"; typeof a>>>String
var a = new String('123') typeof a>>>Object
2.特殊字符:
\' | 单引号 |
\" | 双引号 |
\\ | 反斜杠 |
\n | 换行 |
\r | 回车 |
\t | tab(制表符) |
\b | 退格符 |
\f | 换页符 |
3.属性:
length | 字符串的长度 |
4.方法:
'''charAt(index) 返回在指定位置的字符。str[index]'''
'''charCodeAt(index) 返回在指定的位置的字符的 Unicode 编码。'''
'''concat(s1..sn) 连接两个或更多字符串,并返回新的字符串。'''
'''fromCharCode(u1..un) 将 Unicode 编码转为字符。'''
'''indexOf(str) 返回某个指定的字符串值在字符串中首次出现的位置。没有返回-1'''
'''includes(str) 查找字符串中是否包含指定的子字符串。'''
'''lastIndexOf(str,[start=str.length-1]) 从后向前搜索字符串。没有返回-1'''
'''match(reg) 查找与正则表达式的匹配的字符。如果 regexp 有标志g,则返回数组,没有返回null'''
'''repeat(count) 复制字符串指定次数,并将它们连接在一起返回。'''
'''replace(reg,newstr) 替换regexp匹配到的的子串。'''
'''search(reg) 查找与regrex相匹配的值。返回index。没有返回-1'''
'''slice(strat,[end]) 切片。含头不含尾,支持负索引,str.slice(0)==str'''
'''split(str|reg,[limit]) 把字符串分割为字符串数组。limit用于限制返回数组长度'''
'''startsWith(str,[index=0]) 查看字符串是否以指定的子字符串开头。'''
'''substr(index,[number]) 从起始索引号提取字符串中指定数目的字符。number没指定则一直取到结尾'''
'''substring(from, to) 提取字符串中两个指定的索引号之间的字符。含头不含尾'''
'''toLowerCase() 把字符串转换为小写。'''
'''toUpperCase() 把字符串转换为大写。'''
'''trim() 去除字符串两边的空白'''