Standard library / strings

strings.TrimPrefix()

Removes one exact prefix if present, otherwise returns input unchanged. Expected stdout: 'preGo\n'.

Formal Syntax & Structure

go syntaxgo
func TrimPrefix(s, prefix string) string

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
prefixstringLeading sequence to match.

Return Value

string

Removes one exact prefix if present, otherwise returns input unchanged.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  fmt.Println(string(strings.TrimPrefix("prepreGo", "pre")))}
Go Reference