Notes & TILs
Search…
Splitting strings in Go
Splitting strings in Go is done by using the Split() method. You need to import the strings standard library to use this.

Demo

1
package main
2
​
3
import (
4
"fmt"
5
"strings"
6
)
7
​
8
func main(){
9
var date string = "1999-03-12"
10
date_array = strings.Split(date, "-")
11
​
12
fmt.Println(date_array)
13
}
Copied!
The split() return a Go Array, running this program should print the following:
1
[1999 03 12]
Copied!
Last modified 1mo ago
Copy link
Contents
Demo