last 2 lectures of section 12
last 2 lectures of section 12
This commit is contained in:
19
Section12/96.go
Normal file
19
Section12/96.go
Normal file
@@ -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]))
|
||||||
|
|
||||||
|
}
|
||||||
64
Section12/98.go
Normal file
64
Section12/98.go
Normal file
@@ -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)
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user