字符串的定义
var str="hello world" string类型
var str=new String("hello world"); object类型
ASCII码表
a 97
A 65
"0" 48
空格 32
回车 13
crt+回车 10
97 65 32 48 13 10
string☞API
charAt
功能:返回索引对应的字符,
参数:charAt(索引)
返回值:返回索引对应的字符
charCodeAt
功能:返回索引对应的字符的asc码值,
参数:charCodeAt(索引)
返回值:返回索引对应的字符的asc码值,
console.log(str.charCodeAt(0));
length 字符长度
fromCharCode()
功能:将ASCII码值转换为字符
参数:fromCharCode(asc1,asc2...)
返回值:转换后的字符串
通过string调用
indexOf
功能:查找子串首次出现的位置
参数:indexOf(子串)
返回值:找到返回子串的首字母下标,找不到返回-1
lastIndexof
功能:从末尾查找子串首次出现的位置
参数:lastIndexOf(子串)
返回值:找到返回子串的首字母下标,找不到返回-1
replace
功能:字符串替换,
参数:replace(被替换字符串,替换字符串);
返回值:新字符串
截取字符串
参数:slice(起始位置,结束位置),左闭右开, 支持负数
substring 不支持负数
split
功能:字符串分割函数,将分割的字符串转换为数组,
参数:split(分隔符)
返回值:数组
字符串大小写转换
toLowcase();
toUpperCase();