HiveBrain v1.2.0
Get Started
← Back to all entries
snippetgoCritical

How to strings.Split on newline?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howsplitnewlinestrings

Problem

I'm trying to do the rather simple task of splitting a string by newlines.

This does not work:

temp := strings.Split(result, `\n`)


Any ideas?

Solution

You have to use "\n".

Splitting on `\n, searches for an actual \ followed by n` in the text, not the newline byte.

playground

Context

Stack Overflow Q#25080862, score: 122

Revisions (0)

No revisions yet.