比较两个单词中的字母,看看它们是否有共同的字母
函数WordPass应该将两个单词/字符串作为参数,并寻找它们共同的字母。如果他们有共同的字母,则该功能将返回为true,如果不是,则返回false。
这是我尝试的:
Function wordPass(wordleAnswer As String, guess As String) As Boolean
For i = 1 To Len(wordleAnswer)
For j = 1 To Len(guess)
same = False
If Mid(guess, j, 1) = Mid(wordleAnswer, i, 1) Then
same = True
End If
Next j
Next i
wordPass = same
End Function
The function wordPass is supposed to take two words/strings as parameters and look for letters that they have in common. If they have letters in common, the function returns True, if not, it returns False.
Here is what I tried:
Function wordPass(wordleAnswer As String, guess As String) As Boolean
For i = 1 To Len(wordleAnswer)
For j = 1 To Len(guess)
same = False
If Mid(guess, j, 1) = Mid(wordleAnswer, i, 1) Then
same = True
End If
Next j
Next i
wordPass = same
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以使用
instr
消除一个循环:We can eliminate one loop using
InStr
: