From: D T Date: 2003-06-27T00:14:30+09:00 Subject: Re: String#split(' ') and whitespace (perl user's surprise) --0-641240-1056640468=:67038 Content-Type: text/plain; charset=us-ascii > 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! ) 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 ?! :-) Anyway, you need more control, still need to work on last item after split. Dave --------------------------------- Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! --0-641240-1056640468=:67038 Content-Type: text/html; charset=us-ascii
> 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! )
 
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 ?! :-)
 
Anyway, you need more control, still need to work on last item after split.
 
Dave


Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month! --0-641240-1056640468=:67038--