Standard library / bytes

bytes.TrimPrefix()

Removes one exact prefix if present, otherwise returns input unchanged. The returned slice may alias the input. Expected stdout: 'preGo\n'.

Formal Syntax & Structure

go syntaxgo
func TrimPrefix(s, prefix []byte) []byte

Parameters & Attributes

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

Return Value

[]byte

Removes one exact prefix if present, otherwise returns input unchanged. The returned slice may alias the input.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  fmt.Println(string(bytes.TrimPrefix([]byte("prepreGo"), []byte("pre"))))}
Go Reference