-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Milestone
Description
If I already have a string in memory, there's no simple and efficient way of splitting it into lines.
The naïve approach won't handle \r\n.
strings.Split(s, "\n")Using a bufio.Scanner works but it creates copies instead of slicing the existing string.
var lines []string
sc := bufio.NewScanner(strings.NewReader(s))
for sc.Scan() {
lines = append(lines, sc.Text())
}I'd like a new strings.Lines function similar to strings.Fields for this use-case.
Reactions are currently unavailable