2009-09-29 79 views

回答

15
var str1 = "When I say wall I want to split"; 
var chunks = str1.split("wall"); 

alert(chunks[0]); /* When I say */ 
alert(chunks[1]); /* I want to split */ 
0
var s = str.split("wall"); 
var st1 = s[0]; 
var st2 = s[1]; 
1
var parts = str.split('wall '); 

var st1 = parts[0]; 
var st2 = parts[1]; 
2

只是爲了完整起見,我將添加一個正則表達式回答:

var splits = str.split(/wall /); 
alert("'"+splits[0]+"'"); //'this is part 1 ' 
alert("'"+splits[1]+"'"); //'this is part 2 '