16 Star 68 Fork 53

ShirDon-廖显东/Go语言高级开发与实战-随书代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
array1.go 940 Bytes
一键复制 编辑 原始数据 按行查看 历史
ShirDon-廖显东 提交于 2021-12-28 09:45 +08:00 . commit
//++++++++++++++++++++++++++++++++++++++++
// 《Go语言高级开发与实战》源码
//++++++++++++++++++++++++++++++++++++++++
// Author:廖显东(ShirDon)
// Blog:https://www.shirdon.com/
// 公众号:源码大数据
// 仓库地址:https://gitee.com/shirdonl/goAdvanced
// 仓库地址:https://github.com/shirdonl/goAdvanced
//++++++++++++++++++++++++++++++++++++++++
package main
import "fmt"
//检查字符串是否在切片中
func Exist(target string, array []string) bool {
for _, element := range array {
if target == element {
return true
}
}
return false
}
func main() {
nameList := []string{"Barry", "Shirdon", "Jack"}
str1 := "Barry"
str2 := "Go"
result := Exist(str1, nameList)
fmt.Println("Barry 是否在 nameList 中:", result)
result = Exist(str2, nameList)
fmt.Println("Go是否在 nameList 中:", result)
}
//Barry 是否在 nameList 中: true
//Go是否在 nameList 中: false
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shirdonl/goAdvanced.git
git@gitee.com:shirdonl/goAdvanced.git
shirdonl
goAdvanced
Go语言高级开发与实战-随书代码
0f051d9f4e35

搜索帮助