Golang bytes.IndexFunc() function example
package bytes
IndexFunc interprets given input as a sequence of UTF-8-encoded Unicode code points. It returns the byte index of the search key in the given input of the first Unicode code point satisfying the search and return -1 if there is no match.
Golang bytes.IndexFunc() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
utf8slice := []byte("大世界和小世界")
utf8byteindex := bytes.IndexFunc(utf8slice, func(searchkey rune) bool {
return searchkey == '和'
})
fmt.Printf("和 index num is %d inside the string %s\n", utf8byteindex, string(utf8slice))
}
Output :
和 index num is 9 inside the string 大世界和小世界
Reference :
Advertisement
Something interesting
Tutorials
+20.2k Golang : How to get struct tag and use field name to retrieve data?
+4.9k Unix/Linux : secure copying between servers with SCP command examples
+17.5k Golang : Linked list example
+20.9k Golang : Convert PNG transparent background image to JPG or JPEG image
+16.9k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+12.3k Golang : How to display image file or expose CSS, JS files from localhost?
+25.7k Golang : missing Mercurial command
+41.9k Golang : How do I convert int to uint8?
+9.4k Golang : Create unique title slugs example
+9.1k Golang : How to capture return values from goroutines?
+9.2k Golang : How to control fmt or log print format?