我試圖在字符串匹配后獲取下一個單詞。例如var somestring string = "Hello this is just a random string"匹配我這樣做的詞strings.Contains(somestring, "just")在這種情況下,我想得到“a”。
1 回答

慕少森
TA貢獻2019條經驗 獲得超9個贊
package main
import (
"fmt"
"strings"
)
func main() {
s := "Hello this is just a random string"
// find the index of string "just"
index := strings.Index(s, "just")
fmt.Println(index)
// get next single word after "just"
word := strings.Fields(s[index:])
fmt.Println(word[1])
}
- 1 回答
- 0 關注
- 91 瀏覽
添加回答
舉報
0/150
提交
取消