W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
以下常用方法列表,文檔更新可能滯后于代碼新特性,更多的方法及示例請(qǐng)參考代碼文檔:https://pkg.go.dev/github.com/gogf/gf/v2/container/garray
Append
?的方法是?PushRight
?的別名
Append(value ...string) *StrArray
func ExampleStrArray_Append() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"We", "are", "GF", "fans"})
s.Append("a", "b", "c")
fmt.Println(s)
// Output:
// ["We","are","GF","fans","a","b","c"]
}
At(index int) (value string)
index
?為2的數(shù)據(jù)。func ExampleStrArray_At() {
s := garray.NewStrArrayFrom(g.SliceStr{"We", "are", "GF", "fans", "!"})
sAt := s.At(2)
fmt.Println(sAt)
// Output:
// GF
}
Size
?,分割成多個(gè)數(shù)組,返回值為?[][]string
?。最后一個(gè)數(shù)組包含數(shù)據(jù)的數(shù)量可能小于?Size
?Chunk(size int) [][]string
func ExampleStrArray_Chunk() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
r := s.Chunk(3)
fmt.Println(r)
// Output:
// [[a b c] [d e f] [g h]]
}
Clear() *StrArray
func ExampleStrArray_Clear() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
fmt.Println(s)
fmt.Println(s.Clear())
fmt.Println(s)
// Output:
// ["a","b","c","d","e","f","g","h"]
// []
// []
}
Clone() (newArray *StrArray)
func ExampleStrArray_Clone() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
r := s.Clone()
fmt.Println(r)
fmt.Println(s)
// Output:
// ["a","b","c","d","e","f","g","h"]
// ["a","b","c","d","e","f","g","h"]
}
String
?值。字符串嚴(yán)格區(qū)分大小寫(xiě)。返回值為?bool
?Contains(value string) bool
e
?和?z
?func ExampleStrArray_Contains() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
fmt.Println(s.Contains("e"))
fmt.Println(s.Contains("z"))
// Output:
// true
// false
}
String
?值。字符串不區(qū)分大小寫(xiě)。返回值為?bool
?ContainsI(value string) bool
E
?和?z
?func ExampleStrArray_ContainsI() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
fmt.Println(s.ContainsI("E"))
fmt.Println(s.ContainsI("z"))
// Output:
// true
// false
}
map[string]int
?CountValues() map[string]int
func ExampleStrArray_CountValues() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c", "c", "c", "d", "d"})
fmt.Println(s.CountValues())
// Output:
// map[a:1 b:1 c:3 d:2]
}
startIndex
?,用指定的?value
?進(jìn)行填充。返回值為?error
?Fill(startIndex int, num int, value string) error
index
?為2的地方,用字符串?here
?填充3個(gè)數(shù)據(jù)func ExampleStrArray_Fill() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
s.Fill(2, 3, "here")
fmt.Println(s)
// Output:
// ["a","b","here","here","here","f","g","h"]
}
FilterEmpty() *StrArray
func ExampleStrArray_FilterEmpty() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "", "c", "", "", "d"})
fmt.Println(s.FilterEmpty())
// Output:
// ["a","b","c","d"]
}
index
?的值,返回值有2個(gè)參數(shù),返回值?value
?,和是否找到指定位置的數(shù)據(jù)?found
?,為?true
?則找到,為?false
?則未找到
Get(index int) (value string, found bool)
func ExampleStrArray_Get() {
s := garray.NewStrArrayFrom(g.SliceStr{"We", "are", "GF", "fans", "!"})
sGet, sBool := s.Get(3)
fmt.Println(sGet, sBool)
// Output:
// fans true
}
index
?的位置之后插入值?value
?,返回值為?error
?InsertAfter(index int, value string) error
index
?為1的值之后,插入字符串?here
?func ExampleStrArray_InsertAfter() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d"})
s.InsertAfter(1, "here")
fmt.Println(s.Slice())
// Output:
// [a b here c d]
}
index
?的位置之前插入值?value
?,返回值為?error
?InsertBefore(index int, value string) error
index
?為1的值之前,插入字符串?here
?func ExampleStrArray_InsertBefore() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d"})
s.InsertBefore(1, "here")
fmt.Println(s.Slice())
// Output:
// [a here b c d]
}
[]interface{}
?進(jìn)行返回
Interfaces() []interface{}
[]interface{}
?的內(nèi)容func ExampleStrArray_Interfaces() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
r := s.Interfaces()
fmt.Println(r)
// Output:
// [a b c d e f g h]
}
true
?,如果不是空數(shù)組,則返回?false
?IsEmpty() bool
func ExampleStrArray_IsEmpty() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "", "c", "", "", "d"})
fmt.Println(s.IsEmpty())
s1 := garray.NewStrArray()
fmt.Println(s1.IsEmpty())
// Output:
// false
// true
}
Iterator(f func(k int, v string) bool)
func ExampleStrArray_Iterator() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c"})
s.Iterator(func(k int, v string) bool {
fmt.Println(k, v)
return true
})
// Output:
// 0 a
// 1 b
// 2 c
}
f
?,按升序?qū)?shù)組進(jìn)行遍歷,如果?f
?返回?true
?,則繼續(xù)進(jìn)行遍歷,否則停止遍歷
IteratorAsc(f func(k int, v string) bool)
func ExampleStrArray_Iterator() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c"})
s.Iterator(func(k int, v string) bool {
fmt.Println(k, v)
return true
})
// Output:
// 0 a
// 1 b
// 2 c
}
f
?,按降序?qū)?shù)組進(jìn)行遍歷,如果?f
?返回?true
?,則繼續(xù)進(jìn)行遍歷,否則停止遍歷
IteratorAsc(f func(k int, v string) bool)
func ExampleStrArray_IteratorDesc() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c"})
s.IteratorDesc(func(k int, v string) bool {
fmt.Println(k, v)
return true
})
// Output:
// 2 c
// 1 b
// 0 a
}
gule
?,連接起來(lái)
Join(glue string) string
','
?,將數(shù)組中的字符串連接起來(lái)func ExampleStrArray_Join() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c"})
fmt.Println(s.Join(","))
// Output:
// a,b,c
}
Join(glue string) string
func ExampleStrArray_Len() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
fmt.Println(s.Len())
// Output:
// 8
}
f
?對(duì)數(shù)組進(jìn)行寫(xiě)鎖定
LockFunc(f func(array []string)) *StrArray
func ExampleStrArray_LockFunc() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c"})
s.LockFunc(func(array []string) {
array[len(array)-1] = "GF fans"
})
fmt.Println(s)
// Output:
// ["a","b","GF fans"]
}
json.Marshal
?的?JSON
?格式的序列化接口
MarshalJSON() ([]byte, error)
JSON
?格式的數(shù)據(jù),并對(duì)該數(shù)據(jù)進(jìn)行序列化的操作后,打印出相應(yīng)結(jié)果func ExampleStrArray_MarshalJSON() {
type Student struct {
Id int
Name string
Lessons []string
}
s := Student{
Id: 1,
Name: "john",
Lessons: []string{"Math", "English", "Music"},
}
b, _ := json.Marshal(s)
fmt.Println(string(b))
// Output:
// {"Id":1,"Name":"john","Lessons":["Math","English","Music"]}
}
array
?可以是任意?garray
?或?slice
?類型。?Merge
?和?Append
?的主要區(qū)別是?Append
?僅僅支持?slice
?類型,?Merge
?則支持更多的參數(shù)類型
Merge(array interface{}) *StrArray
func ExampleStrArray_Merge() {
s1 := garray.NewStrArray()
s2 := garray.NewStrArray()
s1.SetArray(g.SliceStr{"a", "b", "c"})
s2.SetArray(g.SliceStr{"d", "e", "f"})
s1.Merge(s2)
fmt.Println(s1)
// Output:
// ["a","b","c","d","e","f"]
}
safe
?為非必需參數(shù),布爾型,是并發(fā)安全的開(kāi)關(guān),缺省值為?False
?NewStrArray(safe ...bool) *StrArray
Safe
?參數(shù),默認(rèn)為非并發(fā)安全設(shè)置func ExampleNewStrArray() {
s := garray.NewStrArray()
s.Append("We")
s.Append("are")
s.Append("GF")
s.Append("Fans")
fmt.Println(s.Slice())
// Output:
// [We are GF Fans]
}
safe
?為非必需參數(shù),布爾型,是并發(fā)安全的開(kāi)關(guān),缺省值為?False
?NewStrArrayFrom(array []string, safe ...bool) *StrArray
Safe
?參數(shù),默認(rèn)為非并發(fā)安全設(shè)置func ExampleNewStrArrayFrom() {
s := garray.NewStrArrayFrom(g.SliceStr{"We", "are", "GF", "fans", "!"})
fmt.Println(s.Slice(), s.Len(), cap(s.Slice()))
// Output:
// [We are GF fans !] 5 5
}
safe
?為非必需參數(shù),布爾型,是并發(fā)安全的開(kāi)關(guān),缺省值為?False
?NewStrArrayFrom(array []string, safe ...bool) *StrArray
Safe
?參數(shù),默認(rèn)為非并發(fā)安全設(shè)置func ExampleNewStrArrayFromCopy() {
s := garray.NewStrArrayFromCopy(g.SliceStr{"We", "are", "GF", "fans", "!"})
fmt.Println(s.Slice(), s.Len(), cap(s.Slice()))
// Output:
// [We are GF fans !] 5 5
}
size
?和?cap
?,創(chuàng)建一個(gè)新數(shù)組。?safe
?為非必需參數(shù),布爾型,是并發(fā)安全的開(kāi)關(guān),缺省值為?False
?NewStrArraySize(size int, cap int, safe ...bool) *StrArray
Size
?為3,?Cap
?為5,并添加數(shù)據(jù)。打印出相應(yīng)的內(nèi)容。此時(shí)沒(méi)有指定 ?Safe
?參數(shù),默認(rèn)為非并發(fā)安全設(shè)置func ExampleNewStrArraySize() {
s := garray.NewStrArraySize(3, 5)
s.Set(0, "We")
s.Set(1, "are")
s.Set(2, "GF")
s.Set(3, "fans")
fmt.Println(s.Slice(), s.Len(), cap(s.Slice()))
// Output:
// [We are GF] 3 5
}
size
?的值?value
?到數(shù)組中。如果大小?size
?是正數(shù),則從數(shù)組的右邊開(kāi)始填充。如果?size
?是負(fù)數(shù),則從數(shù)組的左邊開(kāi)始填充。如果?size
?的大小正好等于數(shù)組的長(zhǎng)度,那么將不會(huì)填充任何數(shù)據(jù)。
Pad(size int, value string) *StrArray
here
?填充到?size
?為7,然后用指定的字符串?there
?將數(shù)組用字符串填充到?size
?為10func ExampleStrArray_Pad() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c"})
s.Pad(7, "here")
fmt.Println(s)
s.Pad(-10, "there")
fmt.Println(s)
// Output:
// ["a","b","c","here","here","here","here"]
// ["there","there","there","a","b","c","here","here","here","here"]
}
value
?為出棧的字符串?dāng)?shù)據(jù)。更新后的數(shù)組數(shù)據(jù)為剩余數(shù)據(jù)。當(dāng)數(shù)組為空時(shí),?found
?為?false
?。
PopLeft() (value string, found bool)
func ExampleStrArray_PopLeft() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d"})
s.PopLeft()
fmt.Println(s.Slice())
// Output:
// [b c d]
}
size
?。如果?size
?比數(shù)組的?size
?大,那么方法將返回?cái)?shù)組中所有的數(shù)據(jù)。如果?size<=0
?或者為空,那么將返回?nil
?PopLefts(size int) []string
func ExampleStrArray_PopLefts() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
r := s.PopLefts(2)
fmt.Println(r)
fmt.Println(s)
// Output:
// [a b]
// ["c","d","e","f","g","h"]
}
found
?將返回?false
?PopRand() (value string, found bool)
func ExampleStrArray_PopRand() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
r, _ := s.PopRand()
fmt.Println(r)
// May Output:
// e
}
size
?個(gè)數(shù)據(jù),返回值為出棧的字符串?dāng)?shù)據(jù)。如果?size<=0
?或者為空,那么將返回?nil
?PopRands(size int) []string
func ExampleStrArray_PopRands() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
r := s.PopRands(2)
fmt.Println(r)
// May Output:
// [e c]
}
value
?為出棧的字符串?dāng)?shù)據(jù)。更新后的數(shù)組數(shù)據(jù)為剩余數(shù)據(jù)。當(dāng)數(shù)組為空時(shí),?found
?為?false
?。
PopRight() (value string, found bool)
func ExampleStrArray_PopRight() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d"})
s.PopRight()
fmt.Println(s.Slice())
// Output:
// [a b c]
}
size
?。如果?size
?比數(shù)組的?size
?大,那么方法將返回?cái)?shù)組中所有的數(shù)據(jù)。如果?size<=0
?或者為空,那么將返回?nil
?PopRights(size int) []string
func ExampleStrArray_PopRights() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
r := s.PopRights(2)
fmt.Println(r)
fmt.Println(s)
// Output:
// [g h]
// ["a","b","c","d","e","f"]
}
PushLeft(value ...string) *StrArray
func ExampleStrArray_PushLeft() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d"})
s.PushLeft("We", "are", "GF", "fans")
fmt.Println(s.Slice())
// Output:
// [We are GF fans a b c d]
}
PushRight(value ...string) *StrArray
func ExampleStrArray_PushRight() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d"})
s.PushRight("We", "are", "GF", "fans")
fmt.Println(s.Slice())
// Output:
// [a b c d We are GF fans]
}
Rand() (value string, found bool)
func ExampleStrArray_Rand() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
fmt.Println(s.Rand())
// May Output:
// c true
}
size
?個(gè)字符串(非刪除式)
Rands(size int) []string
func ExampleStrArray_Rands() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
fmt.Println(s.Rands(3))
// May Output:
// [e h e]
}
slice
?拷貝。
Range(start int, end ...int) []string
index
?為2至5位置的數(shù)據(jù)func ExampleStrArray_Range() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
r := s.Range(2, 5)
fmt.Println(r)
// Output:
// [c d e]
}
index
?處的數(shù)據(jù)。如果?index
?超過(guò)數(shù)組的邊界,則?found
?返回?false
?Remove(index int) (value string, found bool)
index
?為1的數(shù)據(jù)func ExampleStrArray_Remove() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d"})
s.Remove(1)
fmt.Println(s.Slice())
// Output:
// [a c d]
}
value
?。如果?value
?在數(shù)組中被找到,則?found
?返回?true
?,否則?found
?返回?false
?RemoveValue(value string) bool
func ExampleStrArray_RemoveValue() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d"})
s.RemoveValue("b")
fmt.Println(s.Slice())
// Output:
// [a c d]
}
Replace(array []string) *StrArray
func ExampleStrArray_Replace() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"We", "are", "GF", "fans", "!"})
fmt.Println(s.Slice())
s.Replace(g.SliceStr{"Happy", "coding"})
fmt.Println(s.Slice())
// Output:
// [We are GF fans !]
// [Happy coding GF fans !]
}
Replace(array []string) *StrArray
func ExampleStrArray_Reverse() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
fmt.Println(s.Reverse())
// Output:
// ["h","g","f","e","d","c","b","a"]
}
f
?進(jìn)行數(shù)組的讀鎖定
RLockFunc(f func(array []string)) *StrArray
f
?中,對(duì)數(shù)組進(jìn)行遍歷,并打印出數(shù)組元素func ExampleStrArray_RLockFunc() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c", "d", "e"})
s.RLockFunc(func(array []string) {
for i := 0; i < len(array); i++ {
fmt.Println(array[i])
}
})
// Output:
// a
// b
// c
// d
// e
}
index
?,如果沒(méi)有查詢到,則返回-1
Search(value string) int
func ExampleStrArray_Search() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
fmt.Println(s.Search("e"))
fmt.Println(s.Search("z"))
// Output:
// 4
// -1
}
index
?設(shè)置值?value
?,如果?index<0
?或者?index
?超出了數(shù)組的邊界,則返回錯(cuò)誤?error
?Set(index int, value string) error
index
?為2的位置,因?yàn)閿?shù)組長(zhǎng)度限制,最后一個(gè)值未設(shè)置成功func ExampleStrArray_Set() {
s := garray.NewStrArraySize(3, 5)
s.Set(0, "We")
s.Set(1, "are")
s.Set(2, "GF")
s.Set(3, "fans")
fmt.Println(s.Slice())
// Output:
// [We are GF]
}
slice
?數(shù)組內(nèi)容給數(shù)組賦值
SetArray(array []string) *StrArray
func ExampleStrArray_SetArray() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"We", "are", "GF", "fans", "!"})
fmt.Println(s.Slice())
// Output:
// [We are GF fans !]
}
Shuffle() *StrArray
func ExampleStrArray_Shuffle() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
fmt.Println(s.Shuffle())
// May Output:
// ["a","c","e","d","b","g","f","h"]
}
slice
?切片數(shù)據(jù),注意,如果是在并發(fā)安全模式下,返回的是一份拷貝數(shù)據(jù),否則返回的是指向數(shù)據(jù)的指針
Shuffle() *StrArray
func ExampleStrArray_Slice() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
fmt.Println(s.Slice())
// Output:
// [a b c d e f g h]
}
reverse
?控制排序的方向,默認(rèn)為?true
?升序,?false
?為降序
Sort(reverse ...bool) *StrArray
func ExampleStrArray_Sort() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"b", "d", "a", "c"})
a := s.Sort()
fmt.Println(a)
// Output:
// ["a","b","c","d"]
}
less
?對(duì)數(shù)組內(nèi)容進(jìn)行排序。
SortFunc(less func(v1, v2 string) bool) *StrArray
func ExampleStrArray_SortFunc() {
s := garray.NewStrArrayFrom(g.SliceStr{"b", "c", "a"})
fmt.Println(s)
s.SortFunc(func(v1, v2 string) bool {
return gstr.Compare(v1, v2) > 0
})
fmt.Println(s)
s.SortFunc(func(v1, v2 string) bool {
return gstr.Compare(v1, v2) < 0
})
fmt.Println(s)
// Output:
// ["b","c","a"]
// ["c","b","a"]
// ["a","b","c"]
}
string
?,
String() string
string
?,并打印出相應(yīng)的結(jié)果func ExampleStrArray_String() {
s := garray.NewStrArrayFrom(g.SliceStr{"a", "b", "c"})
fmt.Println(s.String())
// Output:
// ["a","b","c"]
}
offset
?和長(zhǎng)度?length
?參數(shù)獲得數(shù)組的切片,注意,如果是在并發(fā)安全模式下,返回拷貝數(shù)據(jù),否則返回指向數(shù)據(jù)的指針。如果偏離值?offset
?是非負(fù)數(shù),則從數(shù)組的開(kāi)始位置進(jìn)行切片,否則從數(shù)組的尾部開(kāi)始切片。
SubSlice(offset int, length ...int)
string
?,并打印出相應(yīng)的結(jié)果func ExampleStrArray_SubSlice() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "d", "e", "f", "g", "h"})
r := s.SubSlice(3, 4)
fmt.Println(r)
// Output:
// [d e f g]
}
Sum() (sum int)
func ExampleStrArray_Sum() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"3", "5", "10"})
a := s.Sum()
fmt.Println(a)
// Output:
// 18
}
Unique() *StrArray
func ExampleStrArray_Unique() {
s := garray.NewStrArray()
s.SetArray(g.SliceStr{"a", "b", "c", "c", "c", "d", "d"})
fmt.Println(s.Unique())
// Output:
// ["a","b","c","d"]
}
json.Unmarshal
?的?UnmarshalJSON
?接口
Unique() *StrArray
byte
?切片,將其賦值給結(jié)構(gòu)體后,進(jìn)行反序列化操作,打印出相應(yīng)的內(nèi)容func ExampleStrArray_UnmarshalJSON() {
b := []byte(`{"Id":1,"Name":"john","Lessons":["Math","English","Sport"]}`)
type Student struct {
Id int
Name string
Lessons *garray.StrArray
}
s := Student{}
json.Unmarshal(b, &s)
fmt.Println(s)
// Output:
// {1 john ["Math","English","Sport"]}
}
UnmarshalValue(value interface{}) error
func ExampleStrArray_UnmarshalValue() {
type Student struct {
Name string
Lessons *garray.StrArray
}
var s *Student
gconv.Struct(g.Map{
"name": "john",
"lessons": []byte(`["Math","English","Sport"]`),
}, &s)
fmt.Println(s)
var s1 *Student
gconv.Struct(g.Map{
"name": "john",
"lessons": g.SliceStr{"Math", "English", "Sport"},
}, &s1)
fmt.Println(s1)
// Output:
// &{john ["Math","English","Sport"]}
// &{john ["Math","English","Sport"]}
}
f
?,對(duì)數(shù)組內(nèi)容進(jìn)行遍歷修改
Walk(f func(value string) string) *StrArray
func ExampleStrArray_Walk() {
var array garray.StrArray
tables := g.SliceStr{"user", "user_detail"}
prefix := "gf_"
array.Append(tables...)
// Add prefix for given table names.
array.Walk(func(value string) string {
return prefix + value
})
fmt.Println(array.Slice())
// Output:
// [gf_user gf_user_detail]
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: