完成,给分吧!哈哈! Private Sub Command1_Click() Text1 = Trim(Text1) a = Split(Text1, " ") For i = 0 To UBound(a) If IsNumeric(a(i)) Then j = j + 1 Next MsgBox j End Sub
关于:lu_yanfeng(阳光) 所说的问题, 如果你不希望在你的数组中产生冗余,那只能做递归调用,将所有的连续空格替换成一个空格。 然后使用,但是这样效率就产生了问题。为此我所做的方法是用冗余来提高效率。 这是无法避免的。下面是用递归写的程序,没有了冗余,也是不错的。 Private Sub Command1_Click() Text1 = Trim(Text1) DelSpace a = Split(Text1, " ") For i = 0 To UBound(a) If IsNumeric(a(i)) Then j = j + 1 Next MsgBox j End SubPrivate Sub DelSpace() If InStr(Text1, " ") Then Text1 = Replace(Text1, " ", " ") Else Exit Sub End If DelSpace End Sub
Private Sub DelSpace() If InStr(Text1, " ") Then Text1 = Replace(Text1, " ", " ") Else Exit Sub End If DelSpace End Sub实在是高
Private Sub Command1_Click()
Text1 = Trim(Text1)
a = Split(Text1, " ")
For i = 0 To UBound(a)
If IsNumeric(a(i)) Then j = j + 1
Next
MsgBox j
End Sub
不好意思,程序好像有错(可以比较肯定地说有错),既然执行
Text1=Trim(Text1)后,a=Split(text1," ")有什么用?
如果有连续的空格在一起,则会产生空字符串作为数组的一个元素。
如:
a = Split("a b cd"," ")
a(0) = "a"
a(1) = "b"
a(2) = "" '空字符串
a(3) = "cd"
for i=1 to 10000000000000
print UP
next i
Trim是去掉前后的空格,而不是当中的。
这样是为了压缩字符串的长度,减少程序运行时间。
如果你不希望在你的数组中产生冗余,那只能做递归调用,将所有的连续空格替换成一个空格。
然后使用,但是这样效率就产生了问题。为此我所做的方法是用冗余来提高效率。
这是无法避免的。下面是用递归写的程序,没有了冗余,也是不错的。
Private Sub Command1_Click()
Text1 = Trim(Text1)
DelSpace
a = Split(Text1, " ")
For i = 0 To UBound(a)
If IsNumeric(a(i)) Then j = j + 1
Next
MsgBox j
End SubPrivate Sub DelSpace()
If InStr(Text1, " ") Then
Text1 = Replace(Text1, " ", " ")
Else
Exit Sub
End If
DelSpace
End Sub
If InStr(Text1, " ") Then
Text1 = Replace(Text1, " ", " ")
Else
Exit Sub
End If
DelSpace
End Sub实在是高