concat(str1,str2,···)
连接字符串
indexOf(str,start)
返回 str 在字符串中首次出现的位置
var str = "hello world";
str.indexOf("hello"); // 0
str.indexOf("o",5); // 7
str.indexOf("World"); // -1
lastIndexOf(str,start)
返回 str 在字符串中最后出现的位置
var str = "hello world";
str.lastIndexOf("hello"); // 0
str.lastIndexOf("o",3); // -1
str.lastIndexOf("o",5); // 4
replace(regexp/substr,replacement)
在字符串中用一些字符替换另一些字符,或替换一个与正则匹配的字串
var str = "I is Allen.";
str.replace("is","am"); // "I am Allen."
slice(start,end)
返回字符串的片段
var str = "I am Jack.";
str.slice(3,7); // "m Ja"
str.slice(3); // "m Jack."
str.slice(3,-3); // "m Ja"
split(separator,limit)
将一个字符串分割为子串,然后将结果作为字符串数组返回
var str = "hello world";
str.split(" "); // ["hello"," world"]
str.split(" ",1); // ["hello"]
substr(start,lenght)
返回一个从指定位置开始的指定长度的字串
var str = "how do you do?";
str.substr(4,2); // "do"
str.substr(4); // "do you do?"
str.substr(4,0); // " "
str.substr(4,-1); // " "
str.substr(-3); // "do?"
substring(start,end)
返回位于 string 对象中指定位置的字串,包含 start 处字符,但不包含 end 处字符
var str = "how do you do?";
str.substring(0,3); // "how"
toLowerCase()
把字符串转换为小写
toUpperCase()
把字符串转换为大写
var str = "How do you do?";
str.toLowerCase(); // "how do you do?"
str.toUpperCase(); // "HOW DO YOU DO?"
PS:博客搬家了,以后不再 CSDN 更新了,见谅。最新博客地址:http://www.cnblogs.com/yjzhu/