Logo

Programming-Idioms

History of Idiom 49 > diff from v14 to v15

Edit summary for version 15 by :

Version 14

2015-09-23, 15:42:20

Version 15

2015-09-23, 15:42:50

Idiom #49 Split a space-separated string

Build list chunks consisting in substrings of input string s, separated by one or more space characters.

Idiom #49 Split a space-separated string

Build list chunks consisting in substrings of input string s, separated by one or more space characters.

Imports
import "strings"
Imports
import "strings"
Code
chunks := strings.Split(s, " ")
Code
chunks := strings.Split(s, " ")
Comments bubble
chunks has type []string.
Warning: you may get empty strings as items in chunks because of leading spaces, trailing spaces, and repeated spaces.
Comments bubble
chunks has type []string.
Warning: you may get empty strings as items in chunks because of leading spaces, trailing spaces, and repeated spaces.
Doc URL
https://golang.org/pkg/strings/#Split
Demo URL
http://play.golang.org/p/Ns0aC1E2v4