字符串常用API
length 长度
concat( )连接
charAt(下标) 获取对应字符下标
charCodeAt(下标)获取字符串的unicode编码
String.fromCharCode(unicode码) 通过unicode码得到字符串
大小写转换
str.toUpperCase( ) 转大写
str.toLowerCase( )转小写
indexOf("字符",start)用法和数组一样
lastIndexOf( )
substr(start,num) 截取子字符串
substring( start,end) 含头不含尾
split(切割符)
trim( )去除字符串两边空格,内部空格不会去除
replace(元素/正则,替换值 ) 替换 默认 只替换一次 正则后面有g则全局替换
str.replace(/Microsoft/, "W3School") 默认
str.replace(/Microsoft/g, "W3School") 全局
字符串两种创建方式
常量:var str="嘀嘀嘀"
构造函数:var str = new String(“hello”)
返回类型是对象
欢迎补充!!!