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
Golang Slice interface and array concatenationHow to include and execute HTML template?Replace numbers by zero from stringHow to add Watermark or Merge two image?Example of Sscan vs Sscanf vs Sscanln from FMT PackageCopy an array by value and reference into another arrayConvert Int data type to Int16 Int32 Int64How to check if a string contains a white space in Golang?Subtract N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time.How to check if a string contains a numbers in Golang?