How to remove all line breaks from a string in Golang?
Removing all line breaks from a string results in the string being displayed in one line.
Remove Line Breaks
Example
// Golang program to remove
// line breaks from string
package main
import (
"fmt"
"strings"
)
func main() {
x := "Hello \nWorld!"
x = strings.Replace(x, "\n", "", -1)
fmt.Println(x)
}
Output
Hello, World !
Most Helpful This Week
Send and Receive values from Channel
Panic: runtime error: index out of range error in Golang
How do you read cookies in an HTTP request with an HTTP client in Go?
Cannot use <variable> (type <type>) as type <new-type> error in Golang
How do you handle HTTP server shutdown gracefully in Go?
Pass an Interface as an argument to a function in Go (Golang)
Golang program for implementation of Merge Sort
Converting Int data type to Float in Go
How do you handle HTTP server caching in Go?
How do you catch panic in Golang?
Most Helpful This Week
How to use array in Go Programming Language?Regular expression to validate the date format in "dd/mm/yyyy"How to kill execution of goroutine?Convert Int data type to Int16 Int32 Int64Convert Float32 to Float64 and Float64 to Float32Sierpinski triangle in Go Programming LanguageExample: Fields and FieldsFunc from BYTES PackageExample: Arrays of Arrays, Arrays of Slices, Slices of Arrays and Slices of SlicesPassing multiple string arguments to a variadic functionRegular expression to extract domain from URL