Golang bytes.TrimPrefix() function example

package bytes

TrimPrefix returns the input slice without the provided leading prefix string(2nd parameter). If the given input slice doesn't start with prefix, the original input slice is returned unchanged.

Golang bytes.TrimPrefix() function usage example

 package main

 import (
 "fmt"
 "bytes"
 )

 func main() {
 str := []byte("Bye Bye!")

 trimmed := bytes.TrimPrefix(str,[]byte("Bye"))

 fmt.Println(string(trimmed))

 fmt.Println("Good " + string(trimmed))
 }

Output :

Bye!

Good Bye!

Reference :

http://golang.org/pkg/bytes/#TrimPrefix

Advertisement