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 handle HTTP requests in Go?
Missing return at end of function error in Golang
Golang program for implementation of Floyd–Warshall Algorithm
Defining a type that satisfies an interface in Go Programming Language
How do you send an HTTP GET request with an HTTP client in Go?
How to read names of all files and folders in current directory?
Most Helpful This Week
Passing multiple string arguments to a variadic functionRegular expression to extract filename from given path in GolangRegular expression to extract numbers from a string in GolangReplace first occurrence of string using RegexpPass different types of arguments in variadic functionHow to check lowercase characters in a string in Golang?How to get struct variable information using reflect package?Regular expression to extract DNS host-name or IP Address from stringHow to convert Colorful PNG image to Gray-scale?How to use function from another file golang?