-
Notifications
You must be signed in to change notification settings - Fork 3
/
string_slice.go
executable file
·61 lines (54 loc) · 1.17 KB
/
string_slice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package sliceKit
import (
"github.com/richelieu-yang/chimera/v3/src/core/strKit"
"strings"
)
// Join []string => string
/*
@param sep 分隔符
e.g.
(nil, "-") => ""
([]string{}, "-") => ""
e.g.1
([]string{"1"}, ";") => "1"
([]string{"0", "1", "2", "3", ""}, "-") => "0-1-2-3-"
*/
var Join func(s []string, sep string) string = strings.Join
// RemoveEmpty
/*
@param trimArgs 是否 先 对每个元素进行trim操作?默认:false
e.g.
(nil) => nil
([]string{""}) => []string{}
*/
func RemoveEmpty(s []string, trimArgs ...bool) []string {
if s == nil {
return nil
}
trimFlag := GetFirstItemWithDefault(false, trimArgs...)
rst := make([]string, 0, len(s))
if trimFlag {
for _, str := range s {
str = strKit.TrimSpace(str)
if strKit.IsNotEmpty(str) {
rst = append(rst, str)
}
}
} else {
for _, str := range s {
if strKit.IsNotEmpty(str) {
rst = append(rst, str)
}
}
}
return rst
}
// ContainsStringIgnoreCase 字符串str是否在切片s中?(不区分大小写)
func ContainsStringIgnoreCase(s []string, str string) bool {
for _, tmp := range s {
if strKit.EqualsIgnoreCase(tmp, str) {
return true
}
}
return false
}