字符串拼接
This commit is contained in:
parent
865e2e5725
commit
0c41cd5bcf
|
@ -2,6 +2,7 @@ package helper
|
|||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func IsContainInArr[T comparable](a T, arr []T) bool {
|
||||
|
@ -31,3 +32,16 @@ func RangeSlice[T ~int | ~uint | ~int64 | ~int8 | ~int16 | ~int32 | ~uint64](sta
|
|||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func StrJoin(s ...string) (str string) {
|
||||
if len(s) == 1 {
|
||||
return s[0]
|
||||
} else if len(s) > 1 {
|
||||
b := strings.Builder{}
|
||||
for _, s2 := range s {
|
||||
b.WriteString(s2)
|
||||
}
|
||||
str = b.String()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -112,3 +112,23 @@ func TestRangeSlice(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrJoin(t *testing.T) {
|
||||
type args struct {
|
||||
s []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantStr string
|
||||
}{
|
||||
{name: "t1", args: args{s: []string{"a", "b", "c"}}, wantStr: "abc"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotStr := StrJoin(tt.args.s...); gotStr != tt.wantStr {
|
||||
t.Errorf("StrJoin() = %v, want %v", gotStr, tt.wantStr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user