go语言字符串练习
Posted itdef
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了go语言字符串练习相关的知识,希望对你有一定的参考价值。
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语言字符串练习的主要内容,如果未能解决你的问题,请参考以下文章