Strip all whitespace from a string

前端 未结 3 1673
心在旅途
心在旅途 2020-12-29 01:31

What is the fastest way to strip all whitespace from some arbitrary string in Go.

I am chaining two function from the string package:

response = stri         


        
3条回答
  •  囚心锁ツ
    2020-12-29 02:17

    I found the simplest way would be to use strings.ReplaceAll like so:

    randomString := "  hello      this is a test"
    fmt.Println(strings.ReplaceAll(randomString, " ", ""))
    
    >hellothisisatest
    

    Playground

提交回复
热议问题