Project

General

Profile

Actions

Feature #4335

closed

String#split for empty string is always empty array

Added by phasis68 (Heesob Park) almost 14 years ago. Updated over 4 years ago.

Status:
Rejected
Assignee:
-
Target version:
[ruby-core:34926]

Description

Here is ruby's behavior:

' '.split('/')
# => [" "]
''.split('/')
# => []
'/'.split('/')
# => []

Here is Python's behavior:

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

Is there any chance to let ''.split('/') return [''] instead of []?


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #3575: String#split is inconsistent with empty string and negative limitCloseddrbrain (Eric Hodel)Actions
Actions #1

Updated by naruse (Yui NARUSE) over 13 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

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 13 years ago

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

Updated by nahi (Hiroshi Nakamura) over 12 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

Actions #4

Updated by sawa (Tsuyoshi Sawada) over 4 years ago

  • Description updated (diff)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0