How to Strip Newline Characters from a String in Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
func main() { | |
var string_a string = "My super \nsweet \nstring has \nmany newline\n characters" | |
fmt.Println(string_a) | |
var string_b string = string_a | |
string_b = strings.Replace(string_b, "\n", "", -1) | |
fmt.Println(string_b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's also
strings.TrimSuffix(string_b, "\r\n")
.In my case tough, can't seem to trim the newline at the end of command output from
cat
on a file.