Logo

Programming-Idioms

Create the list of integers items for the string s containing integers separated by one or more whitespace characters (space, tab, newline).
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "fmt"
import "strconv"
parts := strings.Fields(s)
items := make([]int, len(parts))
for i, part := range parts {
	v, err := strconv.Atoi(part)
	if err != nil {
		return err
	}
	items[i] = v
}
a = map(int, s.split())
items = list(a)
items = s.split.map(&:to_i)