var a="abcdc";
var b="a+d+c";
对象 |
作用 |
例子 |
返回在指定位置的字符 |
alert(a.charAt(3)); //d |
|
返回指定位置的字符的Unicode编码 |
alert(a.charCodeAt(3)); //100 |
|
接受一个或多个指定的Unicode值,然后返回一个或多个字符串。 |
alert(String.fromCharCode(76,77,78)); //LMN |
|
连接字符串。 |
||
返回某个指定的字符串,在字符串中首次出现的位置 |
alert(a.indexOf("c")); //2 |
|
方法可返回一个指定的字符串值最后出现的位置,区分大小写。 |
alert(a.lastIndexOf("c")); //4 |
|
在字符串中检索指定的值,而非位置。 |
var str="Hello world!" alert(str.match("world")) //world |
|
替换与正则表达式匹配的子串。 |
alert(a.replace("ab","aa")); alert(a); //aacd //abcd |
|
检索与正则表达式相匹配的值。 返回位置 |
alert( a.search(/c/)); //2 |
|
从指定的开始位置,到结束位置(不包括)的所有字符串。如果不指定结束位置,则从 指定的开始位置,取到结尾 |
alert(a.slice(1,3)); //bc |
|
将一个字符串分割成数组 |
alert( a.split() instanceof Array); //true alert( b.split("+")); //a,b,c |
|
截取指定长度的字符串 |
alert(a.substr(1,2)); //bc |
|
从指定的开始位置,到结束位置(不包括)的所有字符串。如果不指定结束位置,则从 指定的开始位置,取到结尾 |
alert(a.substring(1,3)); //bc |