关键是你要取出所有的对应项吗?用循环吧 我记得是instrrev函数,具体记不清了,你查查书。 public function Convert(byval a as string) as string 'dim a as string '你要转换的字符 dim b as string dim iLen as integer 'a="dld¥334" b="" iLen = instrRev(a,"¥") '找到最后一个"¥" while(ilen>0) if iLen >0 then msgbox "钱数:" & right(a,len(a)-ilen),"提示信息" else msgbox "没有找到钱数。","提示信息" end if a=left(a,len(a)-ilen) iLen = instrRev(a,"¥") '循环判断 end loop convert=b end function
我簡單地寫一個函數﹐你作為參考. 如你的要求如為: "ddl¥334¥445"取第一個¥后面的字符: str=get_value("ddl¥334¥445",2,"¥")取第二個¥后面的字符: str=get_value("ddl¥334¥445",3,"¥") function get_value(word,n,char) dim str dim s1,s2 str=word s1=instr(1,str,char) '獲取第一個"¥"符號的位置 s2=instr(s1+1,str,char) '獲取第二個"¥"符號的位置 if n=1 then get_value=mid(str,1,s1-1) else if n=2 then get_value=mid(str,s1+1,s2-s1-1) else get_value=mid(str,s2+1,len(str)) end if end if end function
Private Sub Command2_Click() Dim t As String Dim i() As String Dim j As Integer t = "ddl¥334¥445" i = Split(t, "¥") For j = 0 To UBound(i()) Print i(j) Next j End Sub
我记得是instrrev函数,具体记不清了,你查查书。
public function Convert(byval a as string) as string 'dim a as string '你要转换的字符
dim b as string
dim iLen as integer
'a="dld¥334"
b=""
iLen = instrRev(a,"¥") '找到最后一个"¥"
while(ilen>0)
if iLen >0 then
msgbox "钱数:" & right(a,len(a)-ilen),"提示信息"
else
msgbox "没有找到钱数。","提示信息"
end if
a=left(a,len(a)-ilen)
iLen = instrRev(a,"¥") '循环判断
end loop
convert=b
end function
否则,你的数据就会这样。
ddl¥334¥445取出来以后是¥334¥445
¥445我想你是想取出数据的样子是¥445
¥334
吧
最好用数组接收就行。
他的方法更简单。用split函数分拣。
如你的要求如為: "ddl¥334¥445"取第一個¥后面的字符:
str=get_value("ddl¥334¥445",2,"¥")取第二個¥后面的字符:
str=get_value("ddl¥334¥445",3,"¥")
function get_value(word,n,char)
dim str
dim s1,s2
str=word
s1=instr(1,str,char) '獲取第一個"¥"符號的位置
s2=instr(s1+1,str,char) '獲取第二個"¥"符號的位置 if n=1 then
get_value=mid(str,1,s1-1)
else
if n=2 then
get_value=mid(str,s1+1,s2-s1-1)
else
get_value=mid(str,s2+1,len(str))
end if
end if
end function
Dim t As String
Dim i() As String
Dim j As Integer
t = "ddl¥334¥445"
i = Split(t, "¥")
For j = 0 To UBound(i())
Print i(j)
Next j
End Sub