我正在尝试在字符串中获得一些字符。它应该有效,但事实并非如此。
Function countLetter(letter As String, secretWord As String)
MsgBox (Split(secretWord, letter).Length)
countLetter = Split(secretWord, letter).Length - 1
End Function
这里有什么问题?
答案 0 :(得分:7)
Split
没有.Length
属性。使用UBound
表示数组中元素从零开始计数。
Function countLetter(letter As String, secretWord As String)
MsgBox UBound(Split(secretWord, letter)) + 1
countLetter = UBound(Split(secretWord, letter))
End Function