Logo

Programming-Idioms

History of Idiom 38 > diff from v7 to v8

Edit summary for version 8 by :

Version 7

2015-08-20, 15:53:14

Version 8

2015-08-21, 23:14:53

Idiom #38 Extract a substring

Find substring t consisting in characters i (included) to j (excluded) of string s.
(character indexes start at 0 unless specified otherwise)

Idiom #38 Extract a substring

Find substring t consisting in characters i (included) to j (excluded) of string s.
(character indexes start at 0 unless specified otherwise)

Code
t = s[i..j-1] 
Code
t = s[i..j-1] 
Comments bubble
In ruby j is included by default
s = "test"
t = "s[0..1] => "te"
Comments bubble
In ruby j is included by default
s = "test"
t = "s[0..1] => "te"
Doc URL
http://www.ruby-doc.org/core-2.1.1/String.html#method-i-slice
Origin
http://www.ruby-doc.org/core-2.1.1/String.html#method-i-slice