转换string slice

This commit is contained in:
白茶清欢 2023-08-06 15:13:38 +08:00
parent eb97a0b352
commit 020ba99fe8
2 changed files with 30 additions and 0 deletions

View File

@ -477,6 +477,16 @@ type Float64SliceResult struct {
Err error Err error
} }
// StringSliceResult ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:11 2023/8/6
type StringSliceResult struct {
Value []string
Err error
}
// AnySliceResult ... // AnySliceResult ...
// //
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>

View File

@ -923,6 +923,26 @@ func (str String) ToNumberSlice(splitChar ...string) Float64SliceResult {
return str.ToFloat64Slice(splitChar...) 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 ... // ToAnySlice ...
// //
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>