From: Gary Wright Date: 2011-07-31T04:11:44+09:00 Subject: [ruby-core:38614] Re: [Ruby 1.9 - Feature #5120][Open] String#split needs to be logical --Apple-Mail-1-885914486 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Jul 30, 2011, at 12:12 PM, Alexey Muranov wrote: > Here are examples showing a surprising and inconsistent behavior of = String#split method: With only one argument, split discards trailing empty fields. > "aa".split('a') # =3D> [] =3D> three empty fields all trailing and = discarded > "aab".split('a') # =3D> ["", "", "b"] =3D> three fields with no empty trailing fields > "aaa".split('aa') # =3D> ["", "a"]=20 =3D> two fields with no empty trailing field > "aaaa".split('aa') # =3D> [] =3D> all empty fields, all discarded > "aaaaa".split('aa') # =3D> ["", "", "a"]=20 =3D> three fields >=20 > "".split('') # =3D> [] > "a".split('') # =3D> ["a"] zero-legth match results in all characters being returned in array: "ab".split('') #=3D> ['a', 'b'] > What is the definition of *split*? The String#split documentation clearly states that empty trailing fields = are discarded and the special case of a zero-length match. Gary Wright= --Apple-Mail-1-885914486 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Here are examples showing a = surprising and inconsistent behavior of String#split method:

With only one argument, split discards trailing empty = fields.
"aa".split('a')  # = =3D> = []

<empty><a><emp= ty><a><empty> =3D> three empty fields all trailing and = discarded

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

<empty><a><e= mpty><a><b> =3D> three fields with no empty trailing = fields

"aaa".split('aa')  # =3D> ["", "a"] =

<empty><separator>&= lt;a>   =3D> two fields with no empty trailing = field

"aaaa".split('aa')  # = =3D> = []

<empty><aa><empty&g= t;<aa><empty> =3D> all empty fields, all = discarded

"aaaaa".split('aa')=  # =3D> ["", "", "a"] =

<empty><aa><empty>= <aa><a> =3D> three fields


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

zero-legth = match results in all characters being returned in = array:

"ab".split('') #=3D> ['a', = 'b']

What is the definition = of *split*?

The String#split = documentation clearly states that empty trailing fields are discarded = and the special case of a zero-length = match.

Gary Wright
= --Apple-Mail-1-885914486--