2020-09-18 11:36:12 +00:00
---
2020-09-18 11:58:38 +00:00
title: "Split on spaces in Go"
2020-09-18 11:36:12 +00:00
date: 2020-09-18
draft: false
tags:
- go
- golang
images:
2021-05-11 18:40:15 +00:00
- https://opengraph.cluster.fun/opengraph/?siteTitle=Today%20I%20learnt...& title=Split%20on%20spaces%20in%20Go& tags=golang%2Cprogramming%2Carrays& image=https%3A%2F%2Fmarcusnoble.co.uk%2Fimages%2Fmarcus.jpg& twitter=Marcus_Noble_& github=AverageMarcus& website=www.MarcusNoble.co.uk
2020-09-18 11:36:12 +00:00
---
2021-05-11 18:40:15 +00:00
While looking to split a multiline and space separated string and not having any luck with `strings.Split()` I came across this somewhat oddly names function:
2020-09-18 11:36:12 +00:00
```go
import (
"fmt"
"strings"
)
func main() {
input := `This is
a multiline, space
separated string`
output := strings.Fields(input)
fmt.Println(output) // ["This", "is", "a", "multiline,", "space", "separated", "string"]
}
```