2021
05-23
05-23
golang判断key是否在map中的代码
个人常用函数funcIsContain(items[]string,itemstring)bool{for_,eachItem:=rangeitems{ifeachItem==item{returntrue}}returnfalse}使用方法varword:="my"varsentence:=[]string{"my","word","in","a","sentence"}ifIsContain(sentence){//包含}else{//不包含}补充:golang中的正则匹配&判断元素是否在slice里或者数组里1、正则匹配packagemainimport("fmt""regexp")funcmain(){...
继续阅读 >