Quick actions

cmd+k|ctrl+k

Navigation

Languages

string in slice

Snippet info

Language

Go

Visibility

public

Author

luffyke

Created

2016-12-30T02:37:46Z

Updated

2016-12-30T02:37:46Z

package main

import (
    "fmt"
)

func main() {
    myslice := []string{"1","2"}
    fmt.Println(stringInSlice("1", myslice))
    fmt.Println(stringInSlice("3", myslice))
}

func stringInSlice(str string, list []string) bool {
	for _, s := range list {
		if s == str {
			return true
		}
	}
	return false
}
INFO