textBox里面的字符串存到数组
text1里有字符串如下:
3d3
44
55
dd
25r5
我想分成一行行,存到一个字符串数组toola()里面如下
toola(0)=3d3
toola(1)=44
toola(2)=55
.....
下面是我的代码
Private Sub Command1_Click()
Dim i As Integer: Dim cr_n As Integer: Dim str_len As Integer
Dim str_tool As String
Dim toola(100) As String
str_tool = Text1.Text
str_len = Len(str_tool)
For i = 0 To 100 Step 1
cr_n = InStr(1, str_tool, Chr(13))
If cr_n = str_len - cr_n Then
Exit For
End If
toola(i) = Mid(str_tool, 1, str_len - cr_n)
str_tool = Mid(str_tool, str_len - cr_n, str_len)
Next i
Text2.Text = toola(1)
End Sub
大侠们帮忙解决一下,小弟不胜感激
[解决办法]
要看是用什么分割的。换行或者空格,可用split函数直接转
[解决办法]
toola = Split(textBox1.Text, VbCrLf)
[解决办法]
dim s as string
dim total() as string
s=text1
total=split(s,vbcrlf)
dim i as long
for i=0 to ubound(total)
debug.print total(i)
next
[解决办法]
你可以判断下
UBound(toola)可以返回最大的下标。