Golang bytes.Contains() function example
package bytes
Contains reports whether subslice is within search input.
Golang bytes.Contains() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
search_input := []byte("abcdefghi")
key_slice := []byte("abc")
key_slice2 := []byte("xyz")
fmt.Println(bytes.Contains(search_input,key_slice))
fmt.Println(bytes.Contains(search_input,key_slice2))
}
Output :
true
false
Advertisement
Something interesting
Tutorials
+12.6k Golang : flag provided but not defined error
+6.4k PHP : Proper way to get UTF-8 character or string length
+8.8k Yum Error: no such table: packages
+14.8k Golang : Find commonalities in two slices or arrays example
+30.5k Get client IP Address in Go
+12.7k Golang : Sort and reverse sort a slice of bytes
+7.1k Golang : A simple forex opportunities scanner
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+7.5k Golang : How to handle file size larger than available memory panic issue
+9.3k Golang : How to get ECDSA curve and parameters data?
+6.8k Golang : Find the longest line of text example
+17k Golang : How to save log messages to file?