Contains, ContainsAny, Count and EqualFold string functions in Go Language
Contains check weather S1 exist in S2 or not while ContainsAny will check any character of S1 exist in S2.
EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding.
Count counts the number of non-overlapping instances of S1 in S2
Example
// Example of using String Functions in Golang Language
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.ContainsAny("Germany", "G"))
fmt.Println(strings.ContainsAny("Germany", "g"))
fmt.Println(strings.Contains("Germany", "Ger"))
fmt.Println(strings.Contains("Germany", "ger"))
fmt.Println(strings.Contains("Germany", "er"))
fmt.Println(strings.Count("cheese", "e"))
fmt.Println(strings.EqualFold("Cat", "cAt"))
fmt.Println(strings.EqualFold("India", "Indiana"))
}
Output
true
false
true
false
true
3
true
false
Most Helpful This Week
How do you read cookies in an HTTP request with an HTTP client in Go?
How do you handle HTTP client server logging in Go?
How to write backslash in Golang string?
Golang Program to print Triangle of Numbers
Type assertion in Go Programming Language
Golang read file line by line to string
Concurrently printing array elements using goroutines and channels
Golang panic recover example
How do you handle HTTP server HTTP/2 in Go?
Add Method to Struct Type