package main
import (
"fmt"
"strings"
)
func main() {
str := "xyhh_123"
words := strings.Split(str, "_")
index := 1
exists := false
var subOrderId string
for i, value := range words {
if i == index {
exists = true
subOrderId = value
break
}
}
fmt.Println(subOrderId)
if exists {
fmt.Printf("下标 %d 存在\n", index)
} else {
fmt.Printf("下标 %d 不存在\n", index)
}
}