1.charAt ()方法
charAt() 方法可返回指定位置的字符。
语法:stringObject.charAt(index)
var str="Hello world!"
document.write(str.charAt(1))
输出结果: e
2.substr()方法
substr() 方法可在字符串中抽取从 start 下标开始的指定数目的字符。
语法:stringObject.substr(start,length)
var str="Hello world!"
document.write(str.substr(3))
输出结果: lo world!
var str="Hello world!"
document.write(str.substr(3,7))
输出结果: lo worl
3.substring()方法
substring() 方法用于提取字符串中介于两个指定下标之间的字符。
语法:stringObject.substring(start,stop)
var str="Hello world!"
document.write(str.substring(3))
输出结果: lo world!
var str="Hello world!"
document.write(str.substring(3,7))
输出结果: lo w
4.slice()方法
slice() 方法可提取字符串的某个部分,并以新的字符串返回被提取的部分。
语法:stringObject.slice(start,end)
var str="Hello happy world!"
document.write(str.slice(6))
输出结果: happy world!
var str="Hello happy world!"
document.write(str.slice(6,11))
输出结果: happy
5.split()方法
split() 方法用于把一个字符串分割成字符串数组。
语法: stringObject.split(separator,howmany)
var str="1:2:3:4:5"
document.write(str.split(":"))
输出结果: ["1", "2", "3", "4", "5"]
var str="a|b|c"
document.write(str.split("|"))
输出结果: ["a", "b", "c"]