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) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | []byte | Input text or sequence. |
| prefix | []byte | Leading 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")))}