How to trim leading and trailing white spaces of a string?

后端 未结 7 1333
别那么骄傲
别那么骄傲 2021-01-30 02:56

Which is the effective way to trim the leading and trailing white spaces of string variable in Go?

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-30 03:08

    Just as @Kabeer has mentioned, you can use TrimSpace and here is an example from golang documentation:

    package main
    
    import (
        "fmt"
        "strings"
    )
    
    func main() {
        fmt.Println(strings.TrimSpace(" \t\n Hello, Gophers \n\t\r\n"))
    }
    

提交回复
热议问题