strings.SplitN(x, 1)

103 views
Skip to first unread message

Tom Limoncelli

unread,
Jul 4, 2016, 3:37:16 PM7/4/16
to golang-nuts
Does strings.SplitN(x, 1) always return []string{x}?

https://play.golang.org/p/3vDg_BFfY9

If so, I think the docs would be more clear if this was spelled out.
For example...

*** strings.go-OLD Mon Jul 4 15:33:24 2016
--- strings.go Mon Jul 4 15:34:48 2016
***************
*** 266,271 ****
--- 266,272 ----
// The count determines the number of substrings to return:
// n > 0: at most n substrings; the last substring will be the
unsplit remainder.
// n == 0: the result is nil (zero substrings)
+ // n == 1: the result is a list with one item (the value s)
// n < 0: all substrings
func SplitN(s, sep string, n int) []string { return genSplit(s, sep, 0, n) }

Tom
--
Email: t...@whatexit.org Work: tlimo...@StackOverflow.com
Blog: http://EverythingSysadmin.com

Matt Harden

unread,
Jul 4, 2016, 7:25:49 PM7/4/16
to Tom Limoncelli, golang-nuts

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages