首页 > 编程语言 > 详细

go语言字符串练习

时间:2018-07-12 22:25:56      阅读:15      评论:0      收藏:0      [点我收藏+]

标签:ffi   ace   pri   pac   pack   prefix   println   显示   package   

 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语言字符串练习

标签:ffi   ace   pri   pac   pack   prefix   println   显示   package   

原文:https://www.cnblogs.com/itdef/p/9302107.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号