可能重複的字符串:
How do I split this string with JavaScript?如何分割在JavaScript
如何分割在JavaScript字符串?
例如str = "this is part 1 one wall this is part 2 "
現在我想要分割由字分離在2份STR wall
所以想輸出是:
st1 ="this is part 1 "
st2 ="this is part 2 "
可能重複的字符串:
How do I split this string with JavaScript?如何分割在JavaScript
如何分割在JavaScript字符串?
例如str = "this is part 1 one wall this is part 2 "
現在我想要分割由字分離在2份STR wall
所以想輸出是:
st1 ="this is part 1 "
st2 ="this is part 2 "
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 */
var s = str.split("wall");
var st1 = s[0];
var st2 = s[1];
var parts = str.split('wall ');
var st1 = parts[0];
var st2 = parts[1];
只是爲了完整起見,我將添加一個正則表達式回答:
var splits = str.split(/wall /);
alert("'"+splits[0]+"'"); //'this is part 1 '
alert("'"+splits[1]+"'"); //'this is part 2 '
哪裏'one'去了? – SilentGhost 2009-09-29 15:49:09