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

2.1 字符串查询

时间:2018-03-21 23:16:32      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:down   tar   markdown   class   string   prefix   imp   false   efs   

package main

import (
    "fmt"
    "strings"
)

const refString = "Mary had a little lamb"

func main() {

    lookFor := "lamb"
    contain := strings.Contains(refString, lookFor)
    fmt.Printf("The \"%s\" contains \"%s\": %t \n", refString, lookFor, contain)

    lookFor = "wolf"
    contain = strings.Contains(refString, lookFor)
    fmt.Printf("The \"%s\" contains \"%s\": %t \n", refString, lookFor, contain)

    startsWith := "Mary"
    starts := strings.HasPrefix(refString, startsWith)
    fmt.Printf("The \"%s\" starts with \"%s\": %t \n", refString, startsWith, starts)

    endWith := "lamb"
    ends := strings.HasSuffix(refString, endWith)
    fmt.Printf("The \"%s\" ends with \"%s\": %t \n", refString, endWith, ends)

}

/*
The "Mary had a little lamb" contains "lamb": true
The "Mary had a little lamb" contains "wolf": false
The "Mary had a little lamb" starts with "Mary": true
The "Mary had a little lamb" ends with "lamb": true
*/

2.1 字符串查询

标签:down   tar   markdown   class   string   prefix   imp   false   efs   

原文地址:https://www.cnblogs.com/zrdpy/p/8620193.html

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