日期:2014-05-16 浏览次数:20437 次
var a = "hello"; var b = ",world"; var c = a.concat(b); alert(c); //c = "hello,world"
var index1 = a.indexOf("l");   
//index1 = 2   
var index2 = a.indexOf("l",3); //从第三个开始检索,假如不填,则默认从0开始。
//index2 = 3  
//注:indexof()对大小写敏感。var get_char = a.charAt(0); //get_char = "h"
var index1 = lastIndexOf('l');   
//index1 = 3   
var index2 = lastIndexOf('l',2)   
//index2 = 2   var re = new RegExp(/^\w+$/); var is_alpha1 = a.match(re); //is_alpha1 = "hello" var is_alpha2 = b.match(re); //is_alpha2 = null
var sub_string1 = a.substring(1); //sub_string1 = "ello" var sub_string2 = a.substring(1,4); //sub_string2 = "ell"
var sub_string1 = a.substr(1); //sub_string1 = "ello" var sub_string2 = a.substr(1,4); //sub_string2 = "ello"
var result1 = a.replace(re,"Hello"); //result1 = "Hello" var result2 = b.replace(re,"Hello"); //result2 = ",world"
var index1 = a.search(re); //index1 = 0 var index2 = b.search(re); //index2 = -1
var sub_string1 = a.slice(1); //sub_string1 = "ello" var sub_string2 = a.slice(1,4); //sub_string2 = "ell"
var arr1 = a.split("");   
//arr1 = [h,e,l,l,o]   var len = a.length(); //len = 5
var lower_string = a.toLowerCase(); //lower_string = "hello"
var upper_string = a.toUpperCase(); //upper_string = "HELLO"