Standard library / bytes

bytes.Trim()

Removes leading and trailing runes in cutset; cutset is not a literal substring. The returned slice may alias the input. Expected stdout: 'go\n'.

Formal Syntax & Structure

go syntaxgo
func Trim(s []byte, cutset string) []byte

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.
cutsetstringSet of code points to remove from the indicated ends.

Return Value

[]byte

Removes leading and trailing runes in cutset; cutset is not a literal substring. The returned slice may alias the input.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  fmt.Println(string(bytes.Trim([]byte("..go.!"), ".!")))}
Go Reference