在Go with Strings 套件中尋找字元索引
您可以使用Index 函數從字串中擷取字串中字元的索引
用法範例:
package main import ( "fmt" "strings" ) func main() { str := "chars@arefun" char := "@" // Find the index of the character using strings.Index index := strings.Index(str, char) if index != -1 { // If the character was found, split the string based on the index chars := str[:index] arefun := str[index+1:] fmt.Println("Index:", index) fmt.Println("chars:", chars) fmt.Println("arefun:", arefun) } else { fmt.Println("Character not found") } }
輸出:
Index: 5 chars: chars arefun: arefun
以上是如何找到 Go 字串中某個字元的索引?的詳細內容。更多資訊請關注PHP中文網其他相關文章!