Standard library / strings

strings.CutSuffix()

Removes the exact suffix if present and reports success; otherwise returns the input unchanged. Expected stdout: 'log true\n'.

Formal Syntax & Structure

go syntaxgo
func CutSuffix(s, suffix string) (before string, found bool)

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
suffixstringTrailing sequence to match.

Return Value

(before string, found bool)

Removes the exact suffix if present and reports success; otherwise returns the input unchanged.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  a, ok := strings.CutSuffix("log.txt", ".txt")  fmt.Println(string(a), ok)}
Go Reference