去除首尾空格

 
package main 
import (
    "fmt"
    "regexp"
)
func main(){
    ss := fmt.Sprintf(" go go go ")
    res:= regexp.MustCompile(`^\s+|\s+$`).ReplaceAllString(ss,"")
    res = fmt.Sprintf("--%v--",res)
    fmt.Println(res)
}

$ go build str.go 
$ ./str
--go go go--

参考