I'm reading file line by line and like to split line based on substring. But when I use SplitAfterN with read line passed, I'm facing below error,
cannot convert 'variable' (type []string) to type string
where 'variable' = []string type
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
)
func main() {
var fLine []string
FileName := flag.String("fpath", "Default file path", "File path description ")
flag.Parse()
fptr, err := os.Open(*FileName)
if err != nil {
log.Fatal(err)
}
FileScanner := bufio.NewScanner(fptr)
for FileScanner.Scan() {
// Append each line into one buffer while reading
fLine = append(fLine, FileScanner.Text())
splitline := strings.SplitAfterN(fLine, "12345", 2)
fmt.Println("Splited string = ", splitline[1])
}
}
I'm expecting below line to split passed argument (fLine) splitline := strings.SplitAfterN(fread, "12345", 2)