Answers for "how to trim all spaces in golang"

Go
0

go remove whitespace from string

randomString := "  hello      this is a test"
fmt.Println(strings.Replace(randomString, " ", "", -1))

>hellothisisatest
Posted by: Guest on December-04-2020
0

golang eliminate duplicate spaces

space := regexp.MustCompile(`s+`)
str := space.ReplaceAllString("Hello  t n world!", " ")
fmt.Println(str) // "Hello world!"
Posted by: Guest on August-13-2020

Browse Popular Code Answers by Language