How does the slice method work? If I want to write:
x.slice(parameter 1, parameter 2)
what do the parameters specify in terms of what part of x (say it's a
sentence) the program slices?
Thanks!
···
--
Posted via http://www.ruby-forum.com/.
How does the slice method work? If I want to write:
x.slice(parameter 1, parameter 2)
what do the parameters specify in terms of what part of x (say it's a
sentence) the program slices?
Thanks!
--
Posted via http://www.ruby-forum.com/.
ri String#slice Array#slice
robert
On Tue, Feb 15, 2011 at 5:46 PM, Gaba Luschi <friedoysterlover@gmail.com> wrote:
How does the slice method work? If I want to write:
x.slice(parameter 1, parameter 2)
what do the parameters specify in terms of what part of x (say it's a
sentence) the program slices?
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
Thanks - I'm still a little bit confused. Where does the slice
begin/stop slicing?
--
Posted via http://www.ruby-forum.com/.
Thanks - very clear!
--
Posted via http://www.ruby-forum.com/.
It selects the number of elements given by the second parameter,
starting at the index given by the first parameter.
On Tue, Feb 15, 2011 at 11:15 AM, Gaba Luschi <friedoysterlover@gmail.com> wrote:
Thanks - I'm still a little bit confused. Where does the slice
begin/stop slicing?--
Posted via http://www.ruby-forum.com/\.
You pick a starting point to slice and then a number of items to
slice. For example, if you write:
"0123456789".slice(i, size)
then you will slice starting after the `i`-th character, and for
`size` more characters, or until the end of the sequence, whichever
comes first. For example,
"0123456789".slice(5, 3)
will yield "567". We start at "5" because the i = 5th character is
"4", and "5" is right after that. Then we take size = 3 characters in
all, yielding "567".
By contrast, if you wrote,
"abcdefgh".slice(5, 10)
you will get "fgh", because we can't take any more characters after
"h" from the sequence.
~ jf
--
John Feminella
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/johnxf
SO: User John Feminella - Stack Overflow
On Tue, Feb 15, 2011 at 12:15, Gaba Luschi <friedoysterlover@gmail.com> wrote:
Thanks - I'm still a little bit confused. Where does the slice
begin/stop slicing?--
Posted via http://www.ruby-forum.com/\.