diff --git a/define.go b/define.go index 6f869b2..7ae43ca 100644 --- a/define.go +++ b/define.go @@ -477,6 +477,16 @@ type Float64SliceResult struct { Err error } +// StringSliceResult ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 15:11 2023/8/6 +type StringSliceResult struct { + Value []string + Err error +} + // AnySliceResult ... // // Author : go_developer@163.com<白茶清欢> diff --git a/string.go b/string.go index 2ea0012..ff85077 100644 --- a/string.go +++ b/string.go @@ -923,6 +923,26 @@ func (str String) ToNumberSlice(splitChar ...string) Float64SliceResult { return str.ToFloat64Slice(splitChar...) } +// ToStringSlice ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 15:11 2023/8/6 +func (str String) ToStringSlice(splitChar ...string) StringSliceResult { + result := StringSliceResult{ + Value: []string{}, + Err: nil, + } + + isSplit := len(splitChar) > 0 + if !isSplit { + result.Err = util.JSON.UnmarshalWithNumber([]byte(str), &result.Value) + return result + } + result.Value = strings.Split(string(str), splitChar[0]) + return result +} + // ToAnySlice ... // // Author : go_developer@163.com<白茶清欢>