xgngg 发表于 2004-5-10 22:18:00

我需要把不同的数据只用空格分开

我需要把不同的数据同时放在TEXTBOX1中,只用空格分开,每个分开的数据都作为一个参数使用,                                               例如12 34 56 78                       把12赋予A,34赋予B.........

雪山飞狐_lzh 发表于 2004-5-10 22:25:00

用Split函数分割



pVal=Split(TextBox1.Text," ")


A=pVal(0)


B=pVal(1)


........

xgngg 发表于 2004-5-11 07:42:00

我用的是CAD2000,没有split这个函数.

雪山飞狐_lzh 发表于 2004-5-11 10:00:00

如果真的没有可以自己编一个Public Function LeftStr(ByVal String1 As Variant, ByVal String2 As Variant)
On Error Resume Next
       LeftStr = Left(String1, InStr(String1, String2) - 1)
       If Err Then LeftStr = False
End FunctionPublic Function RightStr(ByVal String1 As Variant, ByVal String2 As Variant)
On Error Resume Next
       RightStr = Right(String1, Len(String1) - Len(String2) - InStr(String1, String2) + 1)
       If Err Then RightStr = False
End FunctionPublic Function MySplit(ByVal String1 As Variant, ByVal String2 As Variant)
Dim pStr() As String
Dim pStrs As New Collection
Do While InStr(1, String1, String2) > 0
pStrs.Add LeftStr(String1, String2)
String1 = RightStr(String1, String2)
Loop
pStrs.Add String1
ReDim pStr(pStrs.Count - 1)
For i = 0 To pStrs.Count - 1
pStr(i) = pStrs(i + 1)
Next i
MySplit = pStr
End FunctionPublic Sub test()
For Each i In MySplit("12 23 45", " ")
MsgBox i
Next i
End Sub我以前也不知道可以用Split分割,所以自己编了一个

gdzhou 发表于 2004-8-19 13:34:00

Public Function readlin(ByVal nl As String, ByRef data() As String) As String<BR>Dim i, j As Integer<BR>Dim d(20), s As String<BR>s = " "<BR>i = InStr(1, nl, s)<BR>d(0) = 1<BR>j = 1<BR>While i &lt;&gt; 0<BR>'d()中记录的","出现的位置<BR>d(j) = i<BR>i = InStr(i + 1, nl, s)<BR>j = j + 1<BR>Wend<BR>d(j) = Len(nl) + 1<BR>nn = 0


For i = 1 To j<BR>If d(i) - d(i - 1) &gt; 1 Then<BR>data(nn) = Trim(Mid(nl, d(i - 1), d(i) - d(i - 1)))<BR>nn = nn + 1<BR>End If<BR>Next i<BR>End Function

wyj7485 发表于 2004-10-19 11:59:00

如果中间的空格数不均匀,如下:


1                                       2                                                                       3


12                                34                                                       56


123       345                                       567


这又怎样实现数据分开呢?

wyj7485 发表于 2004-10-19 17:35:00

以上程序如下:


Public Function SplitStr(MainStr As String, Pos As Integer) As String<BR>Dim l, i, j, n, k<BR>Dim StrVal(0 To 100) As Variant<BR>Dim MyStr As String<BR>n = 1: j = 0: i = 0<BR>MyStr = " "


l = Len(MainStr)<BR>While i &lt; l<BR>k = InStr(n, MainStr, " ")<BR>If k = 0 Then k = l + 1<BR>MyStr = Mid(MainStr, n, k - n)<BR>n = InStr(n, MainStr, " ")


If MyStr = "" Then<BR>n = n + 1<BR>i = i + 1<BR>Else<BR>j = j + 1<BR>i = i + Len(MyStr)<BR>StrVal(j) = MyStr<BR>End If


Wend


SplitStr = StrVal(Pos)<BR>End Function


Sub test()


SplitStr("1                       2       3", 1)


End Sub<BR>
页: [1]
查看完整版本: 我需要把不同的数据只用空格分开