標籤:var 練習 顯示 UNC int split repeat upper index
1 package main 2 3 import "fmt" 4 import s"strings" 5 6 var p = fmt.Println 7 8 func main() { 9 p("Contains: ",s.Contains("test","es"))10 p("Count: ",s.Count("test","t"))11 p("hasPrefix: ",s.HasPrefix("test","te"))12 p("HasSuffix: ",s.HasSuffix("test","st"))13 p("index: ",s.Index("test","e"))14 p("Join; ",s.Join([]string{"a","b"},"-"))15 p("Repeat: ",s.Repeat("a",5))16 p("Replace: ",s.Replace("foo","o","0",-1))17 p("Replace: ",s.Replace("foo","o","0",1))18 p("Split: ",s.Split("a-b-c-d-e","-"))19 p("ToLower: ",s.ToLower("TEST"))20 p("ToUpper: ",s.ToUpper("test"))21 p()22 23 p("Len: ",len("hello"))24 p("Char: ","hello"[1])25 }
顯示如下
Contains: true
Count: 2
hasPrefix: true
HasSuffix: true
index: 1
Join; a-b
Repeat: aaaaa
Replace: f00
Replace: f0o
Split: [a b c d e]
ToLower: test
ToUpper: TEST
Len: 5
Char: 101
go語言字串練習