Golang bytes.HasSuffix() function example

package bytes

HasSuffix tests whether the input byte slice ends with suffix.

Golang bytes.HasSuffix() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {
 str := []byte("abcdef")

 fmt.Println(bytes.HasSuffix(str, []byte("abc")))
 fmt.Println(bytes.HasSuffix(str, []byte("bcd")))
 fmt.Println(bytes.HasSuffix(str, []byte("def")))
 }

Output :

false

false

true

Note :

Suffix = something added to the end of something else.

  See also : Golang bytes.HasPrefix() function example

Advertisement