With this code:
"\t\ttest\t\t\t".split(/\t/)
I expect the following result:
=> ["", "", "test", "", "", ""]
But the result is:
=> ["", "", "test"]
Why?
If the limit parameter is omitted, trailing null fields are left off the returned array. If it is negative, they are returned:
# Supply -1 as the limit parameter
"\t\ttest\t\t\t".split(/\t/, -1)
=> ["", "", "test", "", "", ""]
This is detailed in the String.split() documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With