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 do you send an HTTP POST request with an HTTP client in Go?
GO Program to Find the Largest Number Among Three Numbers
Go program to find Name Server (NS) record of a domain
3 Different Examples - How State Works in React?
How to Convert string to integer type in Go?
How do you set headers in an HTTP response in Go?
Most Helpful This Week
How to append text to a file in Golang?How to import and alias package names?How to check lowercase characters in a string in Golang?How to check if a string contains a numbers in Golang?Anonymous Functions in GolangDynamic JSON parser without Struct in GolangDifferent ways to validate JSON stringHow to include and execute HTML template?How can we reverse a simple string in Go?How to Remove duplicate values from Slice?