首页 > 其他 > 详细

2.1 字符串查询

时间:2018-03-21 23:01:37      阅读:188      评论:0      收藏:0      [点我收藏+]
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 字符串查询

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!