Standard library / strings
strings.SplitN()
Splits into at most n pieces; n=0 returns nil and n<0 is unlimited. Expected stdout: '[a|b,c]\n'.
Formal Syntax & Structure
go syntaxgo
func SplitN(s, sep string, n int) []stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | string | Input text or sequence. |
| sep | string | Separator or search sequence. |
| n | int | Maximum result count or number of replacements, as specified. |
Return Value
[]string
Splits into at most n pieces; n=0 returns nil and n<0 is unlimited.
Working Example
Example Snippetgo
package main
import ( "fmt" "strings")
func main() { v := strings.SplitN("a,b,c", ",", 2) fmt.Print("[") for i, x := range v { if i > 0 { fmt.Print("|") } fmt.Print(string(x)) } fmt.Println("]")}