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
| Name | Type | Description |
|---|---|---|
| s | string | Input text or sequence. |
| suffix | string | Trailing 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)}