splitting

D

DMG

Hi,

I suppose that:
".".split(".")
will give me array with two empty strings instead of empty array.

How can I do that?

Thanks,
Dawid
 
D

DMG

#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...
 
L

Luis Lavena

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('.')
=> []
 
B

Benoit Daloze

[Note: parts of this message were removed to make it a legal post.]

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


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('.')
=> []
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top