vb中字符串操作的问题

来源:百度知道 编辑:UC知道 时间:2024/07/06 10:50:10
在text1.text中有一串数字.中间有空格的.例如"1010 0010 1101 1010 1010"

用vb代码如何讲空格之间的数字放入一个数组a(w)中(不包含空格).?并且在text2.text中用a(0) a(1) a(2)...显示来.谢谢.

w = 0
c = 1
r = 0
Do
p = InStr(c, Text1.Text, " ")
If p <> 0 Then
a(w) = Mid(Text1.Text, c, p - c)
Else
a(w) = Mid(Text1.Text, c)
End If
c = p + 1
r = r + 1
Loop Until p = 0
w = 0
Do
Text2.Text = Text2.Text & a(w) & " "
w = w + 1
Loop Until w = r - 1
End If

窗体上放两个Text,一个按钮
Option Explicit

Private Sub Command1_Click()
  Text1.Text = "1010 0010 1101 1010 1010"
  Dim a() As String
  a = Split(Text1.Text, " ")
  Dim i As Integer
  If UBound(a) > 0 Then
    Text2.Text = a(0)
    For i = 1 To UBound(a)
      Text2.Text = Text2.Text & " " & a(i)
    Next
  Else
    Text2.Text = ""
  End If
End Sub

如果还有什么问题,请补充,或发百度消息

最简单的方法:
dim a,i as integer
a=split(text1.text," ")
for i=0 to ubound(a)
text2.tex