1.String对象属性
(1) length:字符串的长度
用法:
var a='abc'
console.log(a.length) // 3
2.String对象的方法
(1) charAt():返回指定位置的字符
var a='abc'
console.log(a.charAt(2)) // c
(2) indexOf():返回指定的字符串首次出现的位置
var a='abcdeabcde'
console.log(a.indexOf('b')) // 1
(3) concat():连接两个或多个字符串
var a='123'
var b='456'
var c='789'
console.log(a.concat(b)) // 1234546
console.log(a.concat(b.concat(c))) //123456789
(4) split(a,b):把字符串分割成字符串数组
a为字符串或正则表达式,b为数组的最大长度(数字)
当a是“”时,则每个字符之间都会被分割
var a='a b c d e f'
document.write(a.split(' ',2)+"<br>") // a,b
document.write(a.split('')) // a, ,b, ,c, ,d, ,e, ,f 连空格都分割
(5) slice(a,b) :截取字符串的片段
a为起始下标,b为结束下标 [a,b)
var a='abcdefg'
console.log(a.slice(2,6)) // cdef
(6) substring(a,b)截取字符串
a为开始下标,b为结束下标 [a,b)
var a='abcdefg'
console.log(a.slice(2,6)) // cdef
(7) substr(a,b)截取字符串
a为起始下标,b为截取的长度
var a='abcdefg'
console.log(a.substr(2,2)) // cd
(8) toLowerCase() 转小写
(9) toUpperCase() 转大写
5951

被折叠的 条评论
为什么被折叠?



