Created
October 10, 2017 09:10
-
-
Save radxene/f05c5abb661a8432b18a0b7994eaa15f to your computer and use it in GitHub Desktop.
Golang - Read Lines From String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"strings" | |
) | |
func ReadStringLines(s string) []string { | |
var lines []string | |
scanner := bufio.NewScanner(strings.NewReader(s)) | |
for scanner.Scan() { | |
lines = append(lines, scanner.Text()) | |
} | |
if err := scanner.Err(); err != nil { | |
fmt.Fprintln(os.Stderr, "reading standard input:", err) | |
} | |
return lines | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment