diff --git a/slice/contains.go b/slice/contains.go index 36469f6..25e064a 100644 --- a/slice/contains.go +++ b/slice/contains.go @@ -36,7 +36,6 @@ func ContainsString(sl []string, v string) bool { return false } - func ContainsSlice(smallSlice, bigSlice []string) bool { for i := 0; i < len(smallSlice); i++ { if !ContainsString(bigSlice, smallSlice[i]) { diff --git a/str/ids.go b/str/ids.go index e4be082..25a1aa3 100644 --- a/str/ids.go +++ b/str/ids.go @@ -6,12 +6,24 @@ import ( "strings" ) -func IdsInt64(ids string) []int64 { +func IdsInt64(ids string, sep ...string) []int64 { if ids == "" { return []int64{} } - arr := strings.Split(ids, ",") + s := "," + if len(sep) > 0 { + s = sep[0] + } + + var arr []string + + if s == " " { + arr = strings.Fields(ids) + } else { + arr = strings.Split(ids, s) + } + count := len(arr) ret := make([]int64, 0, count) for i := 0; i < count; i++ { @@ -26,11 +38,16 @@ func IdsInt64(ids string) []int64 { return ret } -func IdsString(ids []int64) string { +func IdsString(ids []int64, sep ...string) string { count := len(ids) arr := make([]string, count) for i := 0; i < count; i++ { - arr[i] = fmt.Sprintf("%d", ids[i]) + arr[i] = fmt.Sprint(ids[i]) + } + + if len(sep) > 0 { + return strings.Join(arr, sep[0]) } + return strings.Join(arr, ",") } diff --git a/str/str.go b/str/str.go index 8948618..8112319 100644 --- a/str/str.go +++ b/str/str.go @@ -19,4 +19,4 @@ func TrimStringSlice(raw []string) []string { } return arr -} \ No newline at end of file +}