diff --git a/Section12/96.go b/Section12/96.go new file mode 100644 index 0000000..9261762 --- /dev/null +++ b/Section12/96.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" +) + +func main() { + s1 := "I love Golang!" + fmt.Println(s1[2:5]) + + s2 := "我爱戈兰" + fmt.Println(s2[0:2]) + + rs := []rune(s2) + fmt.Printf("%T\n", rs) + + fmt.Println(string(rs[0:3])) + +} diff --git a/Section12/98.go b/Section12/98.go new file mode 100644 index 0000000..23e7833 --- /dev/null +++ b/Section12/98.go @@ -0,0 +1,64 @@ +package main + +import ( + "fmt" + "strings" +) + +func main() { + p := fmt.Println + result := strings.Contains("I love Go Programming!", "love") + p(result) + + result = strings.ContainsAny("success", "xys") + p(result) + + result = strings.ContainsRune("golang", 'g') + p(result) + + n := strings.Count("cheese", "e") + p(n) + + n = strings.Count("Five", "") + p(n) + + p(strings.ToLower("GO PyTHON jaVA")) + p(strings.ToUpper("GO PyTHON jaVA")) + + p("go" == "go") + p("GO" == "go") + p(strings.ToLower("GO") == strings.ToLower("go")) + p(strings.EqualFold("GO", "go")) + + myStr := strings.Repeat("ab", 10) + p(myStr) + + myStr = strings.Replace("192.168.0.1", ".", ":", -1) + p(myStr) + + myStr = strings.ReplaceAll("192.168.0.1", ".", ":") + p(myStr) + + s := strings.Split("a,b,c", ",") + fmt.Printf("%T\n", s) + fmt.Printf("%#v\n", s) + + s = strings.Split("Go for Go!", "") + fmt.Printf("%#v\n", s) + + s = []string{"I", "learn", "Golang"} + myStr = strings.Join(s, "-") + p(myStr) + + myStr = "Orange Green \n Blue Yellow" + fields := strings.Fields(myStr) + fmt.Printf("%T\n", fields) + fmt.Printf("%#v\n", fields) + + s1 := strings.TrimSpace("\t Goodbye Windows, Welcome Linux!\n ") + fmt.Printf("%q\n", s1) + + s2 := strings.Trim("...Hello, Gophers!!!?", ".!?") + fmt.Printf("%q\n", s2) + +}