Logo

Programming-Idioms

History of Idiom 38 > diff from v42 to v43

Edit summary for version 43 by programming-idioms.org:
[Go] Var names s, i, j, t in demo

Version 42

2016-11-13, 23:03:43

Version 43

2016-11-13, 23:06:48

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 := string([]rune(s)[i:j])
Code
t := string([]rune(s)[i:j])
Comments bubble
convert to []rune because some characters are two or more bytes.
Comments bubble
convert to []rune because some characters are two or more bytes.
Demo URL
https://play.golang.org/p/HYgE2xPN1_
Demo URL
https://play.golang.org/p/YREgL01lmW