Excel VBA分裂function不工作
我试图在string中获得一些字符发生。 它应该工作,但不是。
Function countLetter(letter As String, secretWord As String) MsgBox (Split(secretWord, letter).Length) countLetter = Split(secretWord, letter).Length - 1 End Function
这里有什么问题?
Split
没有.Length
属性。 使用UBound
来计算数组中元素的从零开始的计数。
Function countLetter(letter As String, secretWord As String) MsgBox UBound(Split(secretWord, letter)) + 1 countLetter = UBound(Split(secretWord, letter)) End Function