Logo

Programming-Idioms

History of Idiom 46 > diff from v15 to v16

Edit summary for version 16 by :

Version 15

2015-09-02, 16:55:48

Version 16

2015-09-03, 15:41:38

Idiom #46 Extract beginning of string (prefix)

Create string t consisting of the 5 first characters of string s.

Idiom #46 Extract beginning of string (prefix)

Create string t consisting of the 5 first characters of string s.

Code
t = s[0, 5]
# OR
t = s.slice(0, 5)
t = s.slice(0...5)
Doc URL
http://ruby-doc.org/core-2.2.3/String.html#method-i-slice