Project

General

Profile

Actions

Feature #5120

closed

String#split needs to be logical

Added by alexeymuranov (Alexey Muranov) over 13 years ago. Updated over 4 years ago.

Status:
Rejected
Target version:
[ruby-core:38610]

Description

Here are examples showing a surprising and inconsistent behavior of String#split method:

"aa".split('a')  # => []
"aab".split('a')  # => ["", "", "b"]

"aaa".split('aa')  # => ["", "a"] 
"aaaa".split('aa')  # => []
"aaaaa".split('aa')  # => ["", "", "a"] 

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

What is the definition of split? I would suggest something like this:

str1.split(str2) returns the maximal array of non-empty substrings of str1 that can be concatenated with copies of str2 to form str1.

Addition can be made to this definition to make clear what to expect as the result of "baaab".split("aa").


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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0