Logo

Programming-Idioms

History of Idiom 38 > diff from v41 to v42

Edit summary for version 42 by programming-idioms.org:
[Ruby] +DemoURL

Version 41

2016-10-19, 21:18:34

Version 42

2016-11-13, 23:03:43

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)

Illustration

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)

Illustration
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
Doc URL
http://www.ruby-doc.org/core-2.1.1/String.html#method-i-slice
Demo URL
https://repl.it/EWsV/0