请问vb如何将一个字符串中以若干个空格间隔的数据,分别显示在list上?
展开全部
需要先将多个空格转变为一个空格,然后再用split分割,再添加到list中
private function killspace( mystr as string) as string
mystr=replace(mystr, " "," ") '用一个空格替换两个空格
if instr(mystr," ") then killspace = killspace(killspace)'还存在两个连续的空格,则继续替换
end function
Private Sub Command1_Click()
Dim mystr As String, a() As String
mystr = killspace(Text1)
a = Split(mystr)
For i = 0 To UBound(a)
List1.AddItem a(i)
Next
End Sub
private function killspace( mystr as string) as string
mystr=replace(mystr, " "," ") '用一个空格替换两个空格
if instr(mystr," ") then killspace = killspace(killspace)'还存在两个连续的空格,则继续替换
end function
Private Sub Command1_Click()
Dim mystr As String, a() As String
mystr = killspace(Text1)
a = Split(mystr)
For i = 0 To UBound(a)
List1.AddItem a(i)
Next
End Sub
展开全部
Private Sub Command1_Click()
Dim a, b As String
Dim C, I As Integer
a = Text1.Text
B = Replace(a, " ", ",")
C = Split(a)
For i = 0 To UBound(C)
List1.AddItem c(i)
Next i
End Sub
在文本框输入以空格间隔的数据就好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用split 函数 取各个空格间的字符,再添加到list钟即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先用split分割成数组,然后循环赋值到list上就行了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询