dim i as long
dim bbb as string
aaa="123 456 789 abc cde fgh ……"for i=1 to len(aaa)
bbb=trim(left(aaa,instr(aaa," ")))
aaa=trim(mid(aaa,instr(aaa," ")))
list1.additem bbbnext
dim bbb as string
aaa="123 456 789 abc cde fgh ……"for i=1 to len(aaa)
bbb=trim(left(aaa,instr(aaa," ")))
aaa=trim(mid(aaa,instr(aaa," ")))
list1.additem bbbnext
Dim A() as String
A()=Split(欲分解的字符串," ",-1)
注意:该数组是以零开始的。
For I = 0 to UBound(A)-1
List1.AddItem A(I)
Next
所以首先判断“欲分解的字符串”最后一位是否为分隔符,如果不是就加一个分隔符。
Dim I As Integer
Dim sSource As String 'sSource -- 欲分解的字符串
Dim sSubString() As StringIf Right$(sSource,1)<>"" Then
sSource=sSource & " "
End IfsSubString()=Split(sSource," ",-1)For I=0 to UBound(sSubString)-1
List1.AddItem sSubString(I)
Next I
A()=Split(欲分解的字符串," ",-1)
注意:该数组是以零开始的。
For I=0 to UBound(a)-1
List1.AddItem a(I)
Next I
我的意图是想打开多个文件,并把文件的完整路径放到ListBox中。
不知为什么Split函数分不了以空格区分的字符串。
先谢了,我试试,成的话,有分。
Dim strSource As String
Dim strResult As String
strSource = 你的字符串
intOffset = InStr(strSource, " ")
Do While intOffset > 0
strResult = Left(strSource, intOffset - 1)
strSource = Mid(strSource, intOffset + 1)
intOffset = InStr(strSource, " ")
Debug.Print strResult
Loop
If Len(strSource)>0 then strResult=strSource 'hehe,这是剩下的最后一个
"完整路径 文件1.扩展名 文件2.扩展名 文件3.扩展名 ……"
其中是不是以空格分隔的?为什么上面说的函数都分解不了?
请指出!如有源程序,希望能回复我!
M_RET= 0
Do
M_RET = M_RET + 1 '指针后移
M_DATARET = MID(M_STR, M_RET, 1) If M_DATARET <> " " Then
M_DATASTR = M_DATASTR & M_DATARET
Else
M_HOLDDATA(M_NUM) = M_DATASTR
M_DATASTR = ""
M_NUM = M_NUM + 1
End If
End If
Loop Until M_DATARET = "h"
"h"作为结束吧。