vb编写一程序提取字符串中的数字,并把连续的数字作为整体
提示该问答中所提及的号码未经验证,请注意甄别。
1个回答
展开全部
Private Sub Command1_Click() '在text1中输入字符串,单击按钮command1提取,并在窗体中打印结果
Dim a(), f As Boolean
For i = 1 To Len(Text1.Text)
If IsNumeric(Mid(Text1.Text, i, 1)) Then
If f = False Then
f = True
ReDim a(0)
Else
ReDim Preserve a(UBound(a) + 1)
End If
a(UBound(a)) = Mid(Text1.Text, i, 1)
For j = i + 1 To Len(Text1.Text)
If IsNumeric(Mid(Text1.Text, j, 1)) Then
a(UBound(a)) = a(UBound(a)) & Mid(Text1.Text, j, 1)
i = i + 1
Else
Exit For
End If
Next j
End If
Next i
If f = True Then
Print "提取的数字依次为:"
For i = 0 To UBound(a)
Print a(i)
Next i
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询