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
How to trim leading and trailing white spaces of a string in Golang?
How to check if a string contains only letters in Golang?
How to check lowercase characters in a string in Golang?
How to verify a string only contains letters, numbers, underscores, and dashes in Golang?
How to check if a string contains a substring in Golang?
How to check if a string contains a white space in Golang?
Most Helpful This Week
How to check if a map contains a key in Go?What is Rune? How to get ASCII value of any character in Go?Golang Slice interface and array concatenationHow to fetch an Integer variable as String in Go?How to get the current date and time with timestamp in local and other timezones ?How to handle HTTP Get response?How do you write multi-line strings in Go?How To Make an HTTP Server in Golang?How to create Map using the make function in Go?Regular Expression to get a string between parentheses in Golang