# Re: 字串分解的小问题.....

Posted by Honey on November 14, 1998 at 20:48:26:

In Reply to: Re: 字串分解的小问题..... posted by Honey on November 14, 1998 at 16:46:43:

提供以下程式给你参考
在Form1上 放个Command1 Text1
在Text1中输入字串

Private Sub Command1_Click()
Dim Lngi As Long, k As Long, u As Long
Dim yy(), o As Long, PString() As String
ReDim yy(1 To 1)

Me.Cls
yy(1) = 0
o = 1
Text1.Text = Trim(Text1.Text)
'/*去除左右有空白的部分*/
k = Len(Text1.Text) '/*字串总长度*/
For Lngi = 1 To k
u = InStr(Lngi, Text1.Text, " ") '/*寻找空白字串位置*/
'/*u若不为零表示有空白的字串*/
If u Then
If Not Mid(Text1.Text, u + 1, 1) = " " Then
'/*若此空白字串右边不为空白字串*/
o = o + 1
ReDim Preserve yy(1 To o)
yy(o) = u
Lngi = u
End If
Else
o = o + 1
ReDim Preserve yy(1 To o)
yy(o) = k
Exit For
End If
Next
'/*经以上程序 yy阵列中存放了空白字串位置*/
For Lngi = 1 To o
Form1.Print yy(Lngi)
Next

k = UBound(yy) - 1
ReDim PString(k)
For Lngi = 1 To k
PString(Lngi) = Mid(Text1.Text, yy(Lngi) + 1, yy(Lngi + 1) - yy(Lngi))
Next

For Lngi = 1 To k
Form1.Print PString(Lngi)
Next
End Sub

其实这个方法 和先前的比起来 速度也差不多
不过程式比原来长了一些

Follow Ups: