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
Undefined reference to <variable/function> error in Golang
Launches 10 Goroutines and each goroutine adding 10 values to a Channel
Illustration of Sleeping Barber Problem in Golang
Golang read csv file into struct
What is the default HTTP server in Go?
GO language program with an example of Hash Table
GO Program to Check Whether a Number is Palindrome or Not
How do you handle HTTP client server alerting in Go?
How to Iterate Over a Slice in Golang?
Converting Int data type to Float in Go
Most Helpful This Week
How to compare equality of struct, slice and map?How to check if a string contains a numbers in Golang?How to get the current date and time with timestamp in local and other timezones ?How to use function from another file golang?How to Convert string to float type in Go?How to collect information about garbage collection?How To Make HTTP Requests in Go?How to write backslash in Golang string?Find element in a slice and move it to first position?Example to create custom error