Logo

Programming-Idioms

History of Idiom 49 > diff from v23 to v24

Edit summary for version 24 by programming-idioms.org:
[Go] Describe type in comment

Version 23

2016-05-16, 07:32:14

Version 24

2016-05-16, 07:33:08

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.Fields(s)
Code
chunks := strings.Fields(s)
Comments bubble
Fields treats repeated spaces as a single separator.
Comments bubble
chunks has type []string.
Fields treats repeated spaces as a single separator.
Doc URL
https://golang.org/pkg/strings/#Fields
Doc URL
https://golang.org/pkg/strings/#Fields
Demo URL
https://play.golang.org/p/rmGMVkXRcz
Demo URL
https://play.golang.org/p/rmGMVkXRcz