Migrated T.I.L. posts to blog
Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
---
|
||||
layout: post.html
|
||||
title: "T.I.L. Split on spaces in Go"
|
||||
summary: "Today I Learnt: Split on spaces in Go"
|
||||
date: 2020-09-18
|
||||
tags: til go golang
|
||||
|
||||
---
|
||||
|
||||
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:
|
||||
|
||||
```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"]
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user