Golang bytes.TrimSuffix() function example
package bytes
TrimPrefix returns the input slice without the provided trailing suffix string(2nd parameter). If the given input slice doesn't start with suffix, the original input slice is returned unchanged.
Golang bytes.TrimSuffix() function usage example
package main
import (
"fmt"
"bytes"
)
func main() {
str := []byte("Bye Bye!")
trimmed := bytes.TrimSuffix(str,[]byte("Bye!"))
fmt.Println(string(trimmed))
fmt.Println(string(trimmed) + "Dear!")
}
Output :
Bye
Bye Dear!
Reference :
Advertisement
Something interesting
Tutorials
+13.6k Android Studio : Password input and reveal password example
+8.4k Your page has meta tags in the body instead of the head
+5.5k Golang : If else example and common mistake
+17.6k Golang : Upload/Receive file progress indicator
+14.6k Golang : Missing Bazaar command
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example
+14.3k Golang : Simple word wrap or line breaking example
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+21.3k Golang : Create and resolve(read) symbolic links
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+27.5k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+52.6k Golang : How to get struct field and value by name