Hi,
I suppose that:
".".split(".")
will give me array with two empty strings instead of empty array.
How can I do that?
Thanks,
Dawid
Hi,
I suppose that:
".".split(".")
will give me array with two empty strings instead of empty array.
How can I do that?
Thanks,
Dawid
#Ok, instead of
irb(main):065:0> "...text...".split(".")
=> ["", "", "", "text"]
#I should do something like this:
irb(main):066:0> "...text...".split(".",-1)
=> ["", "", "", "text", "", "", ""]
Strange...
There is nothing before or after the period.
irb(main):001:0> " . ".split('.')
=> [" ", " "]
irb(main):002:0> ".".split('.')
=>
On Mar 4, 1:00 pm, DMG <dawid.mar...@gmail.com> wrote:
Hi,
I suppose that:
".".split(".")
will give me array with two empty strings instead of empty array.How can I do that?
--
Luis Lavena
$ ri String#split
str.split(pattern=$;, [limit])
If the limit parameter is omitted, trailing null fields are
suppressed. If limit is a positive number, at most that number of
fields will be returned (if limit is 1, the entire string is
returned as the only entry in an array). If negative, there is no
limit to the number of fields returned, and trailing null fields
are not suppressed.
On 4 March 2010 14:35, Luis Lavena <luislavena@gmail.com> wrote:
On Mar 4, 1:00 pm, DMG <dawid.mar...@gmail.com> wrote:
> Hi,
>
> I suppose that:
> ".".split(".")
> will give me array with two empty strings instead of empty array.
>
> How can I do that?There is nothing before or after the period.
irb(main):001:0> " . ".split('.')
=> [" ", " "]
irb(main):002:0> ".".split('.')
=>--
Luis Lavena