1.func Contains (S, substr string) bool This function is to find whether a character exists in this string, and exists to return true
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Contains ("Widuu", "wi"))//true
Fmt. PRINTLN (Strings. Contains ("wi", "Widuu"))//false
}
2.func Containsany (S, chars string) bool This is the query string contains more than one character
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Containsany ("Widuu", "W&d"))//true
}
3.func Containsrune (s string, R rune) bool, this side of course is the string containing the rune type, where the rune type is UTF8. Runecountstring can fully represent the type of all Unicode characters
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Containsrune ("Widuu", Rune (' W '))//true
Fmt. PRINTLN (Strings. Containsrune ("Widuu")//fasle
}
4.func Count (S, Sep string) int is the output, how many characters are matched in a string
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Count ("Widuu", "UU")//1
Fmt. PRINTLN (Strings. Count ("Widuu", "U"))//2
}
5.func Index (S, Sep string) int This function is to find the string, then return to the current position, enter the string type, and then the position information of int
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Index ("Widuu", "I")//1
Fmt. PRINTLN (Strings. Index ("Widuu", "U"))//3
}
6.func Indexany (S, chars string) int This function is the same lookup, where the string first appears, and returns 1 if it does not exist
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Indexany ("Widuu", "U"))//3
}
7.func Indexbyte (s string, c byte) int, this function is to find the first rough line position, only this time C is byte type, find the return position, can't find the return-1
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Indexbyte ("Hello Xiaowei", ' X ')//6
}
8.func Indexrune (s string, R rune) int, or find location, except this is rune type
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Indexrune ("Widuu", Rune (' W '))//0
}
9.func Indexfunc (S string, F func (rune) bool int This function we can see it, is through the type of conversion to use the function to find the location, we come to the code to see HA
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Indexfunc ("Nihaoma", split))//3
}
Func split (R rune) bool {
if r = = ' A ' {
return True
}
return False
}
10.func lastindex (S, Sep string) int see this You may also understand that the search is the last place to appear, exactly the opposite of index
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Lastindex ("Widuu", "U"))//4
}
11.func Lastindexany (S, chars string) int This is exactly the opposite of Indexany, and it's also the last
Copy Code code as follows:
Import (
"FMT"
"Strings"
)
Func Main () {
Fmt. PRINTLN (Strings. Lastindexany ("Widuu", "U"))//4
}