split string only when two or more spaces occurs.
string="Talk Talk Walk Walk sell sell";
Expected Result after split:
string[0]='Talk Talk';
string[1]='Walk Walk';
string[2]='sell sell';
Thanks
split string only when two or more spaces occurs.
string="Talk Talk Walk Walk sell sell";
Expected Result after split:
string[0]='Talk Talk';
string[1]='Walk Walk';
string[2]='sell sell';
Thanks
Try this if not using RegEx.
var myString = "Talk Talk Walk Walk sell sell";
var result = myString.split(" ");
for (var i = result.length - 1; i >= 0; i--) {
if (result[i] === "") {
result.splice(i, 1);
}
}
The result variable will have an array of split values.
"a b".split(two_spaces) yields ["a", " b"]. Then, you'd have to remove empty elements.