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
Dim i, j As Integer
Dim d(20), s As String
s = " "
i = InStr(1, nl, s)
d(0) = 1
j = 1
While i0
'd()中记录的","出现的位置
d(j) = i
i = InStr(i + 1, nl, s)
j = j + 1
Wend
d(j) = Len(nl) + 1
nn = 0
For i = 1 To j
If d(i) - d(i - 1) > 1 Then
data(nn) = Trim(Mid(nl, d(i - 1), d(i) - d(i - 1)))
nn = nn + 1
End If
Next i
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
Dim l, i, j, n, k
Dim StrVal(0 To 100) As Variant
Dim MyStr As String
n = 1: j = 0: i = 0
MyStr = " "
l = Len(MainStr)
While i < l
k = InStr(n, MainStr, " ")
If k = 0 Then k = l + 1
MyStr = Mid(MainStr, n, k - n)
n = InStr(n, MainStr, " ")
If MyStr = "" Then
n = n + 1
i = i + 1
Else
j = j + 1
i = i + Len(MyStr)
StrVal(j) = MyStr
End If
Wend
SplitStr = StrVal(Pos)
End Function
Sub test()
SplitStr("1                       2       3", 1)
End Sub
页: [1]
查看完整版本: 我需要把不同的数据只用空格分开