Golang format string fmt Sprintf() string segmentation determines the beginning of the string
1.Judge the beginning of a string
package main
import (
"fmt"
"strings"
)
func main() {
myString := "www.topgoer.com"
// Option 1: (Recommended)
if strings.HasPrefix(myString, "www") {
fmt.Println("Hello to you too")
} else {
fmt.Println("Goodbye")
}
}
2.go String splitting
#Split string by spaces
arr := strings.Fields(s)
#Split string by string abc
arr := strings.Split(s,sep)
Format the string fmt. Printf()
s1 :=fmt.Sprintf("%v-%v",1,2)
fmt.Println(s1)
// 1-2