转换string slice
This commit is contained in:
parent
eb97a0b352
commit
020ba99fe8
10
define.go
10
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<白茶清欢>
|
||||
|
20
string.go
20
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<白茶清欢>
|
||||
|
Loading…
Reference in New Issue
Block a user