From: Wesley J Landaker Date: 2003-06-27T01:13:47+09:00 Subject: Re: String#split(' ') and whitespace (perl user's surprise) On Thursday 26 June 2003 9:14 am, D T wrote: > > I think you want strip instead of squeeze: > > > > irb(main):002:0> " I like broccolli ".squeeze > > => " I like brocoli " > > irb(main):003:0> " I like broccolli ".strip > > => "I like broccolli" > > Well, in this case, squeeze and strip is almost the same, > because later, you will split on space char. > ( so squeeze space between first and second item is not a problem at > all ) > > The only problem on squeez is ONLY on the last item > ' A B C D E' after squeeze.split(' ', 3) ==> ['A', 'B', > 'C D E '] last item ( middle and tail will squeez! ) I was referring to the [sometimes unintended] effect of squeeze by default squeezing *all characters*, not just whitespace. ' AAA BB CCCCCC DDDDDDDDDDDDDD EEE'.squeeze.split(' ', 3) => ['A', 'B', 'C D E'] Maybe that's what you want, but I bet that could take you by surprise if you were expecting it to just squeeze whitespace. =) > An avantage squeeze then strip is like, if you want : > irb(main):002:0> 'A,,,,B,,,,,C,,,D,,E,,'.squeeze(',').split(',',3) > ["A", "B", "C,D,E,"] > # can strip do that ?! :-) Heh heh, I didn't say squeeze wasn't useful. ;) In my above example you can squeeze on ' ' and it works like you said: ' AAA BB CCCCCC DDDDDDDDDDDDDD EEE'.squeeze(' ').split(' ', 3) => ["AAA", "BB", "CCCCCC DDDDDDDDDDDDDD EEE"] -- Wesley J. Landaker - wjl@icecavern.net OpenPGP FP: C99E DF40 54F6 B625 FD48 B509 A3DE 8D79 541F F830