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) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | string | Input text or sequence. |
| prefix | string | Leading 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")))}