是我肤浅了,直接用Instr函数或InstrRev就可以。
data = "湖东路99号标力大厦2楼"
data2 = "鼓楼区五四路159号世界金龙大厦5层"
sep = "区"
msgbox instr(data2,sep)
msgbox left(data2, instr(data2,sep))
————————————————————————以下为原文————————————————————————————
不知道是否有更快捷的方法。
需求:如果地址中包括“区”,则输出区和之后的地址;不包括,则输出空值和原地址。
Dim firstString,otherString
data = "湖东路99号标力大厦2楼"
data2 = "鼓楼区五四路159号世界金龙大厦5层"
sep = "区"
divideString data,sep
msgbox firstString&vbCrlf&otherString
divideString data2,sep
msgbox firstString&vbCrlf&otherString
Function divideString(data,sep)
Dim array
array = split(data,sep,-1,1)
if ubound(array) > 0 Then
firstString = array(0)&sep
otherString = Right(data, len(data)-len(array(0)&sep))
else
firstString = ""
otherString = data
end if
End Function