I have a bufio scanner on a StringReader. After I reach a certain line on the Scanner output, I want to read until the end of the reader. Is there any way to achieve this using a simpler way, other than the commented code ?
s := `1
2
3
4
5
6
7`
beyond5 := ""
scanner := bufio.NewScanner(strings.NewReader(s))
for scanner.Scan() {
if strings.Contains(scanner.Text(), "5") {
// Read all lines until EOF from scanner
// and store in beyond5
// for scanner.Scan() {
// beyond5 += scanner.Text()
// beyond5 += "
"
// }
break
}
}
log.Println(beyond5)