From 5f61b5ec2e8df3c81e260c38d11a8749c041b7db Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Fri, 18 Sep 2020 11:36:12 +0000 Subject: [PATCH] Add 'content/posts/golang-split-by-space.md' --- content/posts/golang-split-by-space.md | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 content/posts/golang-split-by-space.md diff --git a/content/posts/golang-split-by-space.md b/content/posts/golang-split-by-space.md new file mode 100644 index 0000000..a46bbed --- /dev/null +++ b/content/posts/golang-split-by-space.md @@ -0,0 +1,29 @@ +--- +title: "Split on spaces in Gp" +date: 2020-09-18 +draft: false +tags: + - go + - golang +images: +- /images/golang-split-by-space.gif +--- + +While looking to split a multiline and space separated string and not having any look 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"] +} +``` \ No newline at end of file