From: mike@... (Mike Stok) Date: 2003-06-26T23:35:50+09:00 Subject: Re: String#split(' ') and whitespace (perl user's surprise) In article <200306260741.40418.wjl@icecavern.net>, Wesley J Landaker wrote: >On Thursday 26 June 2003 6:14 am, Mike Stok wrote: > >> In irb: >> >> ' A 50 3 for 130'.split(' ', 3) >> >> => ["A", "50", " 3 for 130"] >> >> What I'd like Ruby to do >> >> >> ' A 50 3 for 130'.split(' ', 3) >> >> => ["A", "50", "3 for 130"] > >I should have mentioned that as a workaround, you can do this: > >' A 50 3 for 130'.split(' ', 3).map { |x| x.strip } > >I agree you shouldn't have to do that, but it will get you going with >minimal changes. Thanks. A minor nit is that this will destroy trailing spaces on the third field (not relevant in this case, and maybe useful in many cases. :-) I think that my real point was that if there's a special case for splitting a string on ' ' then it should behave the same way as Perl's special case. Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA