优化slince转字符串

This commit is contained in:
白茶清欢 2023-10-25 17:46:15 +08:00
parent 91eca55f87
commit 31780bd924

View File

@ -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)
}