VB中有没有办法将字符串分开?

来源:百度知道 编辑:UC知道 时间:2024/05/27 01:33:20
例如
a="abc,def"
b="123456,78910"
有没有函数可以将逗号前和逗号后的字符串分开?逗号是放在任意的位置上的`

根据你的例子来看,每个字符串只有一个逗号。
如果不是这样,请用swx1995的方法。

如果是,那么,下面的办法效率更好:
dim i as integer,l as integer
i=instr(s,“,”)
l=len(s)
s1=left(s,i-1)
s2=right(s,l-i)
这里s就是原来的,s1、s2就是你要的

Dim p() as string
Dim str as string
Dim i as integer
str = "abc,def,gsh,setywyth,ssfhjjwey,wewtwey,hsdhhs,sgsgs,r,r,twtey"
p = split(str,",")

Debug.Print "LBound of p()=";LBound(p)
Debug.print "UBound of p()=";ubound(p)
Debug.Print "Split String Count:";UBound(p)-LBound(p)
for i = LBound(p) to UBound(p)
debug.print "p(";i;")=";p(i)
next

a1=mid(a,1,instr(a,",")-1)
a2=mid(a,instr(a,",")+1)
b同理
b1=mid(b,1,instr(b,",")-1)
b2=mid(b,instr(b,",")+1)