Golang bytes.TrimRight() function example
package bytes
TrimRight returns a subslice of the input sice by slicing off all trailing UTF-8-encoded Unicode code points that are contained in cutset (2nd parameter).
Golang bytes.TrimRight() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
str := []byte("abcdefg")
trimmed := bytes.TrimRight(str, "dfg")
fmt.Println(string(trimmed))
testtrim := bytes.TrimRight(str, "ab")
fmt.Println(string(testtrim)) // will not work
}
Output :
abcde
abcdefg
Reference :
Advertisement
Something interesting
Tutorials
+40.5k Golang : Convert to io.ReadSeeker type
+10.6k Android Studio : Simple input textbox and intercept key example
+25.6k Golang : convert rune to integer value
+18.5k Golang : Aligning strings to right, left and center with fill example
+5.4k Golang : fmt.Println prints out empty data from struct
+5.2k Golang : Convert lines of string into list for delete and insert operation
+7.3k Golang : Of hash table and hash map
+7.3k Golang : Not able to grep log.Println() output
+5.2k Python : Create Whois client or function example
+13.2k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+11.6k Golang : Display a text file line by line with line number example