This is a creation in Article, where the information may have evolved or changed.
(1) func Contains(s, substr string) bool This function is to find out if a character exists in the string, and there is a return true
[PHP]
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Contains ("Widuu", "wi"))//true
Fmt. PRINTLN (Strings. Contains ("wi", "Widuu"))//false
}
[/php]
(2) func ContainsAny(s, chars string) bool This is whether the query string contains more than one character
[PHP]
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Containsany ("Widuu", "W&d"))//true
}
[/php]
(3) func ContainsRune(s string, r rune) bool , where the side is of course the string contains the rune type, where the rune type is UTF8. Runecountstring can fully represent the type of all Unicode characters
[PHP]
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Containsrune ("Widuu", Rune (' W ')))//true
Fmt. PRINTLN (Strings. Containsrune ("Widuu",))//fasle
}
[/php]
(4) func Count(s, sep string) int The function of this is to output the number of characters that match in a string
[PHP]
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Count ("Widuu", "UU"))//1
Fmt. PRINTLN (Strings. Count ("Widuu", "U"))//2
}
[/php]
(5) func EqualFold(s, t string) bool This is to determine if the s,t two strings are equal UFF8 encoded in the case of a full lowercase
[PHP]
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Equalfold ("Widuu", "Widuu"))//true
}
[/php]
(6) func Fields(s string) []string , the function is to divide the string according to 1:n space, and the last return is []string slice
[PHP]
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Fields ("Hello Widuu Golang"))//out [Hello Widuu Golang]
}
[/php]
(7) func FieldsFunc(s string, f func(rune) bool) []string See, this is based on a custom function split
[PHP]
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Fieldsfunc ("Widuunhellonword", Split)//[Widuu Hello Word] split by n character
}
Func split (S rune) bool {
if s = = ' n ' {
return True
}
return False
}
[/php]
(8) To func HasPrefix(s, prefix string) bool determine whether a string starts with
[PHP]
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Hasprefix ("Widuu_web", "Widuu"))//true
}
[/php]
(9) func HasSuffix(s, suffix string) bool , determine if there is any suffix, return bool value
[PHP]
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Hassuffix ("Nihaowiduu", "Widuu"))//true
}
[/php]