您的位置:首页 > 编程语言 > VB

VBScript,提取字符串中的一部分

2015-11-11 15:55 363 查看
是我肤浅了,直接用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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: