Standard library / bytes

bytes.HasPrefix()

Reports whether the input begins with the literal prefix. Empty prefix matches. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func HasPrefix(s, prefix []byte) bool

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.
prefix[]byteLeading sequence to match.

Return Value

bool

Reports whether the input begins with the literal prefix. Empty prefix matches.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  fmt.Println(bytes.HasPrefix([]byte("report.csv"), []byte("report")))}
Go Reference