Logo

Programming-Idioms

History of Idiom 46 > diff from v22 to v23

Edit summary for version 23 by :
More specific playground link, Comment.

Version 22

2015-11-17, 21:13:05

Version 23

2015-11-30, 12:37:29

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 := string([]rune(s)[:5])
Code
t := string([]rune(s)[:5])
Comments bubble
This "incurs a run-time cost" proportional to len(s).
Comments bubble
This "incurs a run-time cost" proportional to len(s).
Doc URL
https://golang.org/ref/spec#Conversions
Doc URL
https://golang.org/ref/spec#Conversions
Demo URL
http://play.golang.org/p/KvXiBYv9Y6
Demo URL
http://play.golang.org/p/KvXiBYv9Y6