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