Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"strings"
)
func main() {
r, err := os.Open("data.txt")
if err != nil {
log.Fatal(err)
}
defer r.Close()
s, err := excludeLines(r)
if err != nil {
log.Fatal(err)
}
fmt.Println(s)
}
func excludeLines(r io.Reader) (string, error) {
var lines []string
s := bufio.NewScanner(r)
for s.Scan() {
text := s.Text()
if strings.Contains(text, "^") {
continue
}
lines = append(lines, text)
}
err := s.Err()
if err != nil {
return "", errors.Wrap(err, "Scan")
}
return strings.Join(lines, "\n"), nil
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question