vb截取字符串
如:
left$("abcdefg",3)的结果是:"abc"
mid$("abcdefg",2,3)的结果是:"bcd"
right$("abcdefg",3)的结果是:"efg"
Dim strSrc As String
Dim strResult As String
strSrc = "0|下载地址1|/upload/upload2/files/1.text"
strResult = Right(strSrc,Len(strSrc) - InStr(1,strSrc,"/"))
二、
vb截取任意两个
特征字符之间的字符串
111111+22222+33333333+44444+55555+66666…
如何得到任意两个符号”+”之间的字符串,譬如22222
然后复制以下代码:
Private Sub Command1_Click()
End Sub
'BofNum: 起始字符位,EofNum: 终点字符位)
Private Function GetChar(mStr As String,charX As String,BofNum As Integer,EofNum As Integer) As String
'qnames2 = finddoc.MTnames
Dim sArray() As String
'Dim i As Integer
'循环
Dim iCount As Integer
'记录第几个"+"符号
iCount = 1
'For i = 1 To Len(qnames)
' sArray(i-1)= Mid(qnames,iCount,1)
' iCount =iCount + 2
' MsgBox sArray(i-1)
'Next
End Function
三、mid()函数法
aa="abcdA123456Bdff"
asite = instr(aa,"A")
bsite = instrRev(aa,"B")
Response.Write(mid(aa,asite+1,bsite-asite-1))
-----------------------------------------
function cutstr(byval str1 as string,byval StartStr as string,byval EndStr as string) as string
dim i as integer,j as integer,L1 as integer,L2 as integer
l1=len(startstr)
l2=len(endstr)
i=instr(str,startStr)
j=instr(str,endStr)
if (l1*l2=0) or (i*j=0) or (j-i<1) then '如果指定起始字符串与结束字符串有一个为空,或者有一个不存在,或者前后位置不正确,返回源字符串
cutstr=str1
exit function
else
cutstr=mid(str1,i+l1,j-l1-i)
end if
end function
dim str as string,s1 as string,s2 as string,s3 as string
str="[name]ASDADASDSA[year]123456789[number]123456"
s1="[name]"
s2="[year]"
s3="[number]"
msgBox cutstr(str,s1,s2)
msgBox cutstr(str,s2,s3)
---------------------------------------
dim str
wstr=[name]ASDADASDSA[year]123456789[number]123456
str=mid(wstr,instr(wstr,"[name]"),InStrRev(wstr,"[year]") - InStr(wstr,"[name]"))
str1=mid(wstr,"[year]"),"[number]") - InStr(wstr,"[year]"))
-------------------------------------
Private Sub Form_Click()
s = "[name]ASDADASDSA[year]123456789[number]123456"
a = Split(s,"]")
For i = 1 To UBound(a)
Print Split(a(i),"[")(0)
Next
End Sub
-----------
4.更高级的方法,使用正则表达式处理,正则表达式稍微复杂一些,有基础的朋友可以使用。