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