View Single Post
Old 02-01-2013, 11:25 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Yes, but it's easier overall to do as he requested, so that he doesn't have to worry about any empty elements.

Trivial:
Code:
var s = "               test1 test2 test3                                  test4 ";

var arr = s.replace(/\s+/g, " ").replace(/(^\s|\s$)/g,"").split(" ");
First, reduce all multiple spaces to one space. Then trim the space (if any) off the front and back of the string. Then split on space.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote