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
+4.6k Javascript : Detect when console is activated and do something about it
+17.9k Golang : Login and logout a user after password verification and redirect example
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+8.6k Golang : Another camera capture GUI application with GTK and OpenCV
+9.6k Javascript : Read/parse JSON data from HTTP response
+12.7k Golang : Add ASCII art to command line application launching process
+12.7k Android Studio : Highlight ImageButton when pressed on example
+11.5k CodeIgniter : Import Linkedin data
+7.1k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+7.1k Golang : A simple forex opportunities scanner
+37.7k Golang : Comparing date or timestamp
+41.2k Golang : How to count duplicate items in slice/array?