码迷,mamicode.com
首页 > 其他好文 > 详细

Go Example--strings

时间:2018-10-26 22:06:18      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:port   join   hello   标准   ref   nta   lower   code   test   

package main

import (
    "fmt"
    s "strings"
)

var p = fmt.Println

func main() {
    //strings标准库包含的函数
    p("Contains: ", s.Contains("test", "es"))
    p("Count:", s.Count("test", "t"))
    p("HasPrefix", s.HasPrefix("test", "te"))
    p("HasSuffix", s.HasSuffix("test", "st"))
    p("Index", s.Index("test", "e"))
    p("Join", s.Join([]string{"a", "b"}, "-"))
    p("Repeat", s.Repeat("a", 5))
    p("Replace", s.Replace("foo", "o", "0", -1))
    p("Replace", s.Replace("foo", "o", "0", 1))
    p("Split", s.Split("a-b-c-d-e", "-"))
    p("ToLower", s.ToLower("TESt"))
    p("ToUpper", s.ToUpper("teSt"))
    p()
    p("Len:", len("hello"))
    p("Char", "hello"[1])
}

Go Example--strings

标签:port   join   hello   标准   ref   nta   lower   code   test   

原文地址:https://www.cnblogs.com/promenader/p/9858467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!