Splitting

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…

On Mar 4, 1:00 pm, DMG [email protected] 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(’.’)
=> []

$ 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs