我想在单词“and”之后分隔字符串。我用来做这个,我写下面的函数
Public Function find(separate_text) As Variant
Dim i As Integer
Dim text As String
text = CStr(separate_text)
ReDim returned(InStr(text, "and") To Len(CStr(text))) As Variant
For i = InStr(CStr(text), "and") To Len(CStr(text)) - 4
returned(i) = Mid(text, i + 4, 1)
Next i
find = returned
End Function
当我想要打电话时:
MsgBox CStr(find(example))
导致13错误(不匹配)。问题出在哪里?
答案 0 :(得分:3)
试试这个。如果要返回separate_text的第一部分,请在第三行返回splittext(0)
Public Function MyFind(separate_text As String) As String
splittext = Split(separate_text, "and")
MyFind = LTrim(splittext(1))
End Function