From 020ba99fe8fe1a95035876d95bd9a04af94ecab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 6 Aug 2023 15:13:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E6=8D=A2string=20slice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- define.go | 10 ++++++++++ string.go | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) 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<白茶清欢>