1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| package main
import ( "fmt" "strings" "unicode" )
func main() { TestLastIndexFunc() }
func TestContains() { fmt.Println(strings.Contains("seafood", "foo")) fmt.Println(strings.Contains("seafood", "bar")) fmt.Println(strings.Contains("seafood", "")) fmt.Println(strings.Contains("", "")) fmt.Println(strings.Contains("jonson郑2008", "郑")) }
func TestContainsAny() { fmt.Println(strings.ContainsAny("team", "i")) fmt.Println(strings.ContainsAny("failure", "u & i")) fmt.Println(strings.ContainsAny("foo", "")) fmt.Println(strings.ContainsAny("", "")) }
func TestContainsRune() { fmt.Println(strings.ContainsRune("一丁丂", '丁')) fmt.Println(strings.ContainsRune("一丁丂", 19969)) }
func TestCount() { fmt.Println(strings.Count("cheese", "e")) fmt.Println(strings.Count("one", "")) }
func TestHasPrefix() { fmt.Println(strings.HasPrefix("1000phone news", "1000")) fmt.Println(strings.HasPrefix("1000phone news", "1000a")) }
func TestHasSuffix() { fmt.Println(strings.HasSuffix("1000phone news", "news")) fmt.Println(strings.HasSuffix("1000phone news", "new")) }
func TestIndex() { fmt.Println(strings.Index("chicken", "ken")) fmt.Println(strings.Index("chicken", "dmr")) }
func TestIndexAny() { fmt.Println(strings.IndexAny("abcABC120", "教育基地A")) }
func TestIndexByte() { fmt.Println(strings.IndexByte("123abc", 'a')) }
func TestIndexRune() { fmt.Println(strings.IndexRune("abcABC120", 'C')) fmt.Println(strings.IndexRune("It培训教育", '教')) }
func TestIndexFunc() { f := func(c rune) bool { return unicode.Is(unicode.Han , c) } fmt.Println(strings.IndexFunc("Hello123,中国" , f)) }
func TestLastIndex() { fmt.Println(strings.LastIndex("jonson learn english", "e")) fmt.Println(strings.Index("go gopher", "go")) fmt.Println(strings.LastIndex("go gopher", "go")) fmt.Println(strings.LastIndex("go gopher", "rodent")) }
func TestLastIndexAny() { fmt.Println(strings.LastIndexAny("chicken", "aeiouy")) fmt.Println(strings.LastIndexAny("crwth", "aeiouy")) }
func TestLastIndexByte() { fmt.Println(strings.LastIndexByte("abcABCA123", 'A')) }
func TestLastIndexFunc() { f := func(c rune) bool { return unicode.Is(unicode.Han, c) } fmt.Println(strings.LastIndexFunc("Hello,世界", f)) fmt.Println(strings.LastIndexFunc("Hello,world中国人", f)) }
|