Standard library / strings

strings.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 string) bool

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
prefixstringLeading 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 (  "fmt"  "strings")
func main() {  fmt.Println(strings.HasPrefix("report.csv", "report"))}
Go Reference