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) string

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
suffixstringTrailing 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")))}
Go Reference