Logo

Programming-Idioms

History of Idiom 49 > diff from v15 to v16

Edit summary for version 16 by :

Version 15

2015-09-23, 15:42:50

Version 16

2015-10-29, 14:05:14

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.

Code
$chunks = preg_split("/ +/", $s);
Code
$chunks = preg_split("/ +/", $s);
Comments bubble
To match one ore more spaces, use preg_split instead of explode.
Comments bubble
To match one ore more spaces, use preg_split instead of explode.
Doc URL
http://php.net/manual/en/function.preg-split.php
Doc URL
http://php.net/manual/en/function.preg-split.php
Code
chunks = s.split(" ")
Code
chunks = s.split(" ")
Doc URL
https://docs.python.org/2/library/stdtypes.html
Doc URL
https://docs.python.org/2/library/stdtypes.html
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
Doc URL
https://golang.org/pkg/strings/#Split
Demo URL
http://play.golang.org/p/Ns0aC1E2v4
Demo URL
http://play.golang.org/p/Ns0aC1E2v4
Code
String[] chunks = s.split("\\s+");
Code
String[] chunks = s.split("\\s+");