Standard library / bytes
bytes.TrimSuffix()
Removes one exact suffix if present, otherwise returns input unchanged. The returned slice may alias the input. Expected stdout: 'Go.txt\n'.
Formal Syntax & Structure
go syntaxgo
func TrimSuffix(s, suffix []byte) []byteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | []byte | Input text or sequence. |
| suffix | []byte | Trailing sequence to match. |
Return Value
[]byte
Removes one exact suffix if present, otherwise returns input unchanged. The returned slice may alias the input.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt")
func main() { fmt.Println(string(bytes.TrimSuffix([]byte("Go.txt.txt"), []byte(".txt"))))}