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 :
Advertisement
Something interesting
Tutorials
+20.7k Golang : Read directory content with os.Open
+6.3k Javascript : Generate random key with specific length
+3.7k Golang : Switch Redis database redis.NewClient
+5.9k Golang : Detect variable or constant type
+13.3k Golang : Date and Time formatting
+12.2k Golang : calculate elapsed run time
+22.2k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+5.8k Golang : List all packages and search for certain package
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+15.2k Golang : How to check if IP address is in range
+29.3k Golang : Save map/struct to JSON or XML file
+12.1k Golang : md5 hash of a string