golang 字符串处理

func main(){
  var p := fmt.Println
  var s := strings
  p("Contains: ",s.Contains("test","es")) //true   p("Count: ",s.Count("test","t")) //2   p("hasPrefix: ",s.HasPrefix("test","te")) //true   p("HasSuffix: ",s.HasSuffix("test","st"))     //true   p("index: ",s.Index("test","e"))          //1   p("Join; ",s.Join([]string{"a","b"},"-"))     //a-b   p("Repeat: ",s.Repeat("a",5))            //aaaaa   p("Replace: ",s.Replace("foo","o","0",-1))    //f00   p("Replace: ",s.Replace("foo","o","0",1))     //f0o   p("Split: ",s.Split("a-b-c-d-e","-"))       //[a,b,c,d,e]   p("ToLower: ",s.ToLower("TEST"))          //test   p("ToUpper: ",s.ToUpper("test"))          //TEST   p("Len: ",len("hello"))               //5   p("Char: ","hello"[1])                // 101
}

posted on 2021-03-16 16:09  Kurenoki  阅读(80)  评论(0)    收藏  举报

导航