Golang bytes.TrimLeft() function example

package bytes

TrimLeft returns a subslice of the input slice by slicing off all leading UTF-8-encoded Unicode code points contained in the filter set (2nd parameter)

Golang bytes.TrimLeft() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {
 str := []byte("abcdefg")
 trimmed := bytes.TrimLeft(str, "ab")
 fmt.Println(string(trimmed))


 testtrim := bytes.TrimLeft(str, "fg")
 fmt.Println(string(testtrim)) // will not work
 }

Output :

cdefg

abcdefg

Reference :

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

Advertisement