This is a creation in Article, where the information may have evolved or changed.
function :Join(a []string, sep string) string
Description : Separates the elements in a string slice from the character sep and merges them into a single string and returns
Example :
func main() { str := []string{"Hello", "World", "Good"} fmt.Println(strings.Join(str, " "))}
Program Output Hello World good
function :LastIndex(s, sep string) int
Description : Determines the position of the last occurrence of the character Sep in the string s, if the index of the SEP position is successfully returned, if the character Sep is not in the string s then return-1
Example :
func main() { str := "Hello World" fmt.Println(strings.LastIndex(str, "l"))}
Program Output 9
function : Repeat (S string, Count int) string
Description : Merges the count string s into a single string and returns
Example :
func main() { str := "Hello " fmt.Println(strings.Repeat(str, 5))}
Program output Hello hello hello hello hello
function : Replace (S, old, new string, n int) string
description : Replace the first n of the character old in the string s with the new character and return the replaced string, or N-1 if you want to replace all
Example :
func main() { str := "hi hi hi are you ok" fmt.Println(strings.Replace(str, "hi", "ok", 3))}
Program output OK ok ok
function : Split (S, Sep string) []string
Description : Splits a string in string s into a string slice of several elements with the character Sep as a delimiter, and returns a string slice
Example :
func main() { str := "one,two,three" for _, v := range strings.Split(str, ",") { fmt.Println(v) }}
Program output One, one, three
function : Splitafter (S, Sep string) []string
Description : Splits a string in string s into several string slices with character Sep as a delimiter and preserves the delimiter in the original string and returns a string slice
Example :
func main() { str := "one,two,three" for _, v := range strings.SplitAfter(str, ",") { fmt.Println(v) }}
Program output One, one, three