From 31780bd924d46a3127415dad51c25e9a3a1690f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 25 Oct 2023 17:46:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96slince=E8=BD=AC=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array.go | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/array.go b/array.go index 0d5f8a8..43fef7a 100644 --- a/array.go +++ b/array.go @@ -289,10 +289,38 @@ func (at *Array) Has(input interface{}) int { // Author : go_developer@163.com<白茶清欢> // // Date : 16:57 2023/9/28 -func (at *Array) ToString() string { +func (at *Array) ToString() StringResult { if at.IsNil() { - return "" + return StringResult{ + Value: "", + Err: nil, + } + } + byteData, err := json.Marshal(at.convertResult) + return StringResult{ + Value: string(byteData), + Err: err, + } +} + +// ToStringWithSplit 数组按照指定分隔符转为字符串 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 17:42 2023/10/25 +func (at *Array) ToStringWithSplit(split string) StringResult { + if at.IsNil() { + return StringResult{ + Value: "", + Err: nil, + } + } + strList := make([]string, 0) + for _, item := range at.convertResult { + strList = append(strList, fmt.Sprintf("%v", item)) + } + return StringResult{ + Value: strings.Join(strList, split), + Err: nil, } - byteData, _ := json.Marshal(at.convertResult) - return string(byteData) }