Standard Library Utilities
Strings Helpers
The strings package has small helpers for searching, replacing, and changing text.
Strings Helpers
strings_helpers.go
package main
import (
"fmt"
"strings"
)
func main() {
var phrase =
hasGo := strings.Contains(phrase, "go")
upper := strings.ToUpper(phrase)
slug := strings.ReplaceAll(phrase, " ", "-")
fmt.Println("phrase=", phrase)
fmt.Println("hasGo=", hasGo)
fmt.Println("upper=", upper)
fmt.Println("slug=", slug)
}
package main
import (
"fmt"
"strings"
)
func main() {
var phrase =
hasGo := strings.Contains(phrase, "go")
upper := strings.ToUpper(phrase)
slug := strings.ReplaceAll(phrase, " ", "-")
fmt.Println("phrase=", phrase)
fmt.Println("hasGo=", hasGo)
fmt.Println("upper=", upper)
fmt.Println("slug=", slug)
}
package main
import (
"fmt"
"strings"
)
func main() {
var phrase =
hasGo := strings.Contains(phrase, "go")
upper := strings.ToUpper(phrase)
slug := strings.ReplaceAll(phrase, " ", "-")
fmt.Println("phrase=", phrase)
fmt.Println("hasGo=", hasGo)
fmt.Println("upper=", upper)
fmt.Println("slug=", slug)
}
string helper
A string helper is a library function that performs a common text operation.