Golang bytes.IndexAny() function example
package bytes
IndexAny interprets the input slice as a sequence of UTF-8-encoded Unicode code points. It returns the byte index of the first occurrence in the input slice of any of the Unicode code points search key. It returns -1 if chars is empty or if there is no code point(search key) in common.
Golang bytes.IndexAny() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
search_input := []byte("abcd和efghi")
indexany := bytes.IndexAny(search_input, "和") // if 和 is not available, indexany value will be -1
fmt.Printf("Print everything after index number : %d [%s]\n", indexany, string(search_input[indexany:]))
}
Output :
Print everything after index number : 4 [和efghi]
Advertisement
Something interesting
Tutorials
+12.7k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+9.6k Golang : Validate IPv6 example
+31.7k Golang : How to convert(cast) string to IP address?
+8.8k Golang : On lambda, anonymous, inline functions and function literals
+9.4k Golang : Apply Histogram Equalization to color images
+12.7k Android Studio : Highlight ImageButton when pressed on example
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+33.7k Golang : All update packages with go get command
+9.7k Golang : Find correlation coefficient example
+5.6k PHP : Fix Call to undefined function curl_init() error
+17.9k Golang : Login and logout a user after password verification and redirect example
+16.5k Golang : Execute terminal command to remote machine example