【发布时间】:2019-08-19 02:35:51
【问题描述】:
如何获取从某个位置/某个偏移开始的字符串中的子字符串的索引,例如:
package main
import (
"fmt"
"strings"
)
func main() {
string := "something.value=something=end"
index1 := strings.Index(string, "value=")
fmt.Println(index1) // prints 10
// index2 = ... How do I get the position of the second =, 25?
}
PHP 中的类似偏移量int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
【问题讨论】:
-
只需对字符串进行子切片。
-
也许this 会有所帮助,但我真的不知道您的预期结果是什么。你想知道每个
=在字符串中的位置吗?