常用的字符串方法
一、功能类
1、split(separator, [howmany]) 字符串分割 (IE6+)
separator 按此参数分割,参数缺失时,返回原字符串,参数为空字符串时,分割每个字符
howmany 最大分割份数,返回分割后的前 howmany 个分割项
2、substr(start, length) 从指定位置截取指定长度的字符串, 返回新字符串 (IE6+)
3、 substring(start, end) 不允许负数,从字符串中截取指定字符串, 返回新字符串 (IE6+)
4、slice(start, end) 允许负数,从字符串中截取指定字符串, 返回新字符串 (IE6+)
5、 toLowerCase() / toUpperCase() 字符串转小/大写 (IE6+)
6、toLocaleLowerCase() / toLocaleUpperCase() 因少数语言会为Unicode大小写转换应用特殊的规则,故遵循本地规则转小/大写 (IE6+)
7、 concat() 字符串拼接, 会先做隐式转换 (IE6+)
separator 按此参数分割,参数缺失时,返回原字符串,参数为空字符串时,分割每个字符
howmany 最大分割份数,返回分割后的前 howmany 个分割项
2、substr(start, length) 从指定位置截取指定长度的字符串, 返回新字符串 (IE6+)
3、 substring(start, end) 不允许负数,从字符串中截取指定字符串, 返回新字符串 (IE6+)
4、slice(start, end) 允许负数,从字符串中截取指定字符串, 返回新字符串 (IE6+)
5、 toLowerCase() / toUpperCase() 字符串转小/大写 (IE6+)
6、toLocaleLowerCase() / toLocaleUpperCase() 因少数语言会为Unicode大小写转换应用特殊的规则,故遵循本地规则转小/大写 (IE6+)
7、 concat() 字符串拼接, 会先做隐式转换 (IE6+)
"abc".concat('d', 'e') // "abcde"
"abc".concat(1-'a') // "abcNaN"
"abc".concat([1,2,3]) // "abc1,2,3"
"abc".concat({a: 1}) // "abc[object Object]"
"abc".concat(function(){}) // "abcfunction (){}"
8、indexOf(subString) / lastIndexOf(subString) 判断目标字符串在字符串的位置 (IE6+, 与Array的兼容性不同)
9、search(str | reg) 检索子串,返回下标,类似indexOf,支持正则 (IE6+)
10、match(str | reg) 检索并返回子串,支持正则 (IE6+)
11、replace(str | reg, str | fn) 字符串替换(IE6+)
12、charAt(index) 返回指定位置的字符 (IE6+)
13、charCodeAt(index) 返回指定位置字符的Unicode编码(0~65535) (IE6+)
14、trim() 去除头尾空格,返回新字符串 (IE9+)
"abc".concat(1-'a') // "abcNaN"
"abc".concat([1,2,3]) // "abc1,2,3"
"abc".concat({a: 1}) // "abc[object Object]"
"abc".concat(function(){}) // "abcfunction (){}"
8、indexOf(subString) / lastIndexOf(subString) 判断目标字符串在字符串的位置 (IE6+, 与Array的兼容性不同)
9、search(str | reg) 检索子串,返回下标,类似indexOf,支持正则 (IE6+)
10、match(str | reg) 检索并返回子串,支持正则 (IE6+)
11、replace(str | reg, str | fn) 字符串替换(IE6+)
12、charAt(index) 返回指定位置的字符 (IE6+)
13、charCodeAt(index) 返回指定位置字符的Unicode编码(0~65535) (IE6+)
14、trim() 去除头尾空格,返回新字符串 (IE9+)
// 以下的兼容性不足以投入开发,不多介绍
localeCompare 根据本地规则比较字符串(IE11+)
fromCodePoint (noIE)
includes 识别字符串是否在其他字符串中 (noIE)
startsWith / endsWith 判断字符串以指定字符开头/结尾 (noIE)
codePointAt (noIE)
repeat 生成一串重复多次的字符串 (noIE)
normalize (noIE)
padStart / padEnd (targetLength [padString]) 字符串补全 (noIE)
fromCodePoint (noIE)
includes 识别字符串是否在其他字符串中 (noIE)
startsWith / endsWith 判断字符串以指定字符开头/结尾 (noIE)
codePointAt (noIE)
repeat 生成一串重复多次的字符串 (noIE)
normalize (noIE)
padStart / padEnd (targetLength [padString]) 字符串补全 (noIE)
二、样式类(直接体现在HTML中,不常用)
1、big() 大号字体显示字符串(IE6+)
2、small() 小字号来显示字符串(IE6+)
3、blink() 显示闪动的字符串(IE6+)
4、bold() 粗体显示字符串(IE6+)
5、fixed() 打字机文本显示字符串(IE6+)
6、fontcolor() 指定的颜色来显示字符串(IE6+)
7、fontsize() 指定的尺寸来显示字符串(IE6+)
8、strike() 删除线来显示字符串(IE6+)
9、italics() 斜体显示字符串(IE6+)
10、link() 显示为链接(IE6+)
11、sub() 显示在底部,常用于公式(IE6+)
12、sup() 显示在顶部,常用于公式(IE6+)
2、small() 小字号来显示字符串(IE6+)
3、blink() 显示闪动的字符串(IE6+)
4、bold() 粗体显示字符串(IE6+)
5、fixed() 打字机文本显示字符串(IE6+)
6、fontcolor() 指定的颜色来显示字符串(IE6+)
7、fontsize() 指定的尺寸来显示字符串(IE6+)
8、strike() 删除线来显示字符串(IE6+)
9、italics() 斜体显示字符串(IE6+)
10、link() 显示为链接(IE6+)
11、sub() 显示在底部,常用于公式(IE6+)
12、sup() 显示在顶部,常用于公式(IE6+)
