我有字符串的动态切片,例如{“0s”,“1s”,“2s”,“3s”,“4s”}。
我有动态索引切片,例如{1,2,3}。
所以我只需要切片中索引为1,2和3的元素。
请注意,索引切片和数据切片都是动态的。
package main
import (
"fmt"
)
func main() {
indexes := []uint8{1, 2, 3} //dynamic slice. maybe different elements and count
data := []string{"0s", "1s", "2s", "3s", } //dynamic slice. maybe different elements and count
// I need convert data to {"1s", "2s", "3s"} using indexes (dynamic) slice
fmt.Println(data)
fmt.Println(indexes)
}
这里 游乐场 网址 https://play.golang.org/p/Vj0Vl5va4LP
jeck猫
慕婉清6462132
有只小跳蛙
繁星点点滴滴
相关分类