我正在尝试创建一个不和谐的机器人来检查消息是否包含存储在数组中的字符串。我尝试使用 for 循环,但它没有工作,因为它永远持续下去,我想减少代码行,有什么办法吗?switch { case strings.Contains(mContent, characterss[0]): currentCharacter = characterss[0] currentDescription = descriptions[0] currentImage = images[0] isCorrect = true case strings.Contains(mContent, characterss[1]): currentCharacter = characterss[1] currentDescription = descriptions[1] currentImage = images[1] isCorrect = true case strings.Contains(mContent, characterss[2]): currentCharacter = characterss[2] currentDescription = descriptions[2] currentImage = images[2] isCorrect = true case strings.Contains(mContent, characterss[3]): currentCharacter = characterss[3] currentDescription = descriptions[3] currentImage = images[3] isCorrect = true case strings.Contains(mContent, characterss[4]): currentCharacter = characterss[4] currentDescription = descriptions[4] currentImage = images[4] isCorrect = true case strings.Contains(mContent, characterss[5]): currentCharacter = characterss[5] currentDescription = descriptions[5] currentImage = images[5] isCorrect = true case strings.Contains(mContent, characterss[6]): currentCharacter = characterss[6] currentDescription = descriptions[6] currentImage = images[6] isCorrect = true }
1 回答
HUH函数
TA贡献1836条经验 获得超4个赞
只需使用一个循环:
for i := 0; i <= 6; i ++ {
if strings.Contains(mContent, characeterss[i]) {
currentCharacter = characterss[i]
currentDescription = descriptions[i]
currentImage = images[i]
isCorrect = true
break
}
}
- 1 回答
- 0 关注
- 77 浏览
添加回答
举报
0/150
提交
取消