在Go中修剪字符串变量的开头和结尾空白的有效方法是什么?
例如,
package main import ( "fmt" "strings" ) func main() { s := "\t Hello, World\n " fmt.Printf("%d %q\n", len(s), s) t := strings.TrimSpace(s) fmt.Printf("%d %q\n", len(t), t) }
输出:
16 "\t Hello, World\n " 12 "Hello, World"