Standard library / strings

strings.CutPrefix()

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

Formal Syntax & Structure

go syntaxgo
func CutPrefix(s, prefix string) (after string, found bool)

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
prefixstringLeading sequence to match.

Return Value

(after string, found bool)

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

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  a, ok := strings.CutPrefix("id:7", "id:")  fmt.Println(string(a), ok)}
Go Reference