trim 除掉一个字串中的字头或字尾 不可打印字符 二重循环
二重循环
func trimNonPrintingCharacters(s string) string { l := []string{"\t", "\n", "\r", " "} for _, v := range l { s = strings.Trim(s, v) for _, u := range l { s = strings.Trim(s, u) } } return s }
func Test_trimNonPrintingCharacters(t *testing.T) { type args struct { s string } s1 := ` name string args args` s1_ := ` name string args args` tests := []struct { name string args args want string }{ // TODO: Add test cases. {name: "1", args: args{s: s1}, want: s1_}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := trimNonPrintingCharacters(tt.args.s); got != tt.want { t.Errorf("trimNonPrintingCharacters() = %v, want %v", got, tt.want) } }) } }