How remove \n from lines


file, _ := os.Open("x.txt")
    f := bufio.NewReader(file)

    for {
        read_line, _ := ReadString('\n')

        // other code what work with parsed line...

end it add \n on every line , end program to work , only work with last line…

Please put example, i try anything end any solution what i find here not work for me.


You can slice off the last character:

read_line = read_line[:len(read_line)-1]

Perhaps a better approach is to use the strings library:

read_line = strings.TrimSuffix(read_line, "\n")

Answered By – Alex Lew

Answer Checked By – Senaida (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.