Another delicate problem.
irb(main):001:0> “abcde”.split(/…/)
=> ["", “”, “e”]
irb(main):002:0> “abcde”.split(/./)
=> []
Why is the second result empty?
I would have expected to see some empty strings.
···
–
Simon Strandgaard
Another delicate problem.
irb(main):001:0> “abcde”.split(/…/)
=> ["", “”, “e”]
irb(main):002:0> “abcde”.split(/./)
=> []
Why is the second result empty?
I would have expected to see some empty strings.
–
Simon Strandgaard
irb(main):002:0> "abcde".split(/./)
=>
Why is the second result empty?
svg% ri String#split
----------------------------------------------------------- String#split
str.split(pattern=$;, [limit]) => anArray
------------------------------------------------------------------------
[...]
If the _limit_ parameter is omitted, trailing null fields are
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^n¤
supressed. If _limit_ is a positive number, at most that number of
^^^^^^^^^
fields will be returned (if _limit_ is +1+, the entire string is
returned as the only entry in an array). If negative, there is no
limit to the number of fields returned, and trailing null fields
are not supressed.
[...]
svg%
you have only null fields in the result
Guy Decoux
irb(main):002:0> “abcde”.split(/./)
=>Why is the second result empty?
svg% ri String#split
----------------------------------------------------------- String#split
str.split(pattern=$;, [limit]) => anArray[…]
If the limit parameter is omitted, trailing null fields are
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^n¤
supressed. If limit is a positive number, at most that number of
^^^^^^^^^
[snip]
you have only null fields in the result
Ahh… I see. I just wondered what was going on.
I look at RI, but not carefully enough.
Thanks Guy… I lost count of how many beers…