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 check UPPERCASE characters in a string in Golang?
How to verify a string only contains letters, numbers, underscores, and dashes in Golang?
How to remove special characters from a string in GoLang?
How to trim leading and trailing white spaces of a string in Golang?
How to check string contains uppercase lowercase character in Golang?
How to check if a string contains a white space in Golang?
Most Helpful This Week
Regular expression to extract DNS host-name or IP Address from stringHow can I convert a string variable into Boolean, Integer or Float type in Golang?User Defined Function Types in GolangHow to include and execute HTML template?Example of Switch Case with Break in For LoopRegular expression to validate phone numberHow to create a photo gallery in Go?How to check pointer or interface is nil?Regular expression to extract date(YYYY-MM-DD) from stringDifferent ways for Integer to String Conversions