Feature #4335

String#split for empty string is always empty array

Added by Heesob Park over 4 years ago. Updated over 3 years ago.

[ruby-core:34926]
Status:Rejected
Priority:Normal
Assignee:-

Description

=begin
Here is ruby's behavior:

C:\work>irb
irb(main):001:0> ' '.split('/')
=> [" "]
irb(main):002:0> ''.split('/')
=> []
irb(main):003:0> '/'.split('/')
=> []

Here is python's behavior:
Python 2.4.3 (#1, Jun 11 2009, 14:09:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

' '.split('/')
[' ']
''.split('/')
['']
'/'.split('/')
['', '']

Is there any chance of ''.split('/') returns [''] instead of []?
=end


Related issues

Related to Ruby trunk - Feature #3575: String#split is inconsistent with empty string and negative limit Closed 07/15/2010

History

#1 Updated by Yui NARUSE over 4 years ago

  • Status changed from Open to Feedback

=begin
We don't think we should follow Python's result
and your this proposal doesn't have enough reason to change current behavior even if it breaks compatibility.

I don't say there is no chance but it should be hard that you can show such strong reason.
=end

#2 Updated by Nobuyoshi Nakada over 4 years ago

=begin
'/'.split('/', -1) returns ["", ""].
I don't think it's necessary to be default.
=end

#3 Updated by Hiroshi Nakamura over 3 years ago

  • Description updated (diff)
  • Status changed from Feedback to Rejected

It's intended feature, and -1 is prepared for your purpose as Nobu said. #3575

Also available in: Atom PDF