VB 输入一串字符,有数字和非数字.将连续数字作为一个整数,依次放到数组A.
来源:百度知道 编辑:UC知道 时间:2024/06/05 16:03:39
统计共有多少个整数.并输出他们.
比如输入a123%456 789asdf
a(1)=123
a(2)=456
a(3)=789
那么输入的S为3,内容为123 456 789
打错了.是输出的S为3
Dim szText
szText = "a123%456 789asdf"
Dim oRegExp
Set oRegExp = CreateObject("VBScript.RegExp")
oRegExp.Global=True
oRegExp.IgnoreCase=True
oRegExp.Pattern="([0-9]+)"
Set oMatchs = oRegExp.Execute(szText)
Dim a(),S
S=0
If oMatchs.count>0 Then
S = oMatchs.count
ReDim a(S-1)
For Each oMatch In oMatchs
a(iCount) = oMatch.value
Next
End If
MsgBox S
Dim myStr As String, myTemp As String, myOutput() As String, a() As String, i As Integer, s As Integer
myStr = InputBox("请输入字符串", "数据输入", "a123%456 789asdf ")
For i = 1 To Len(myStr)
myTemp = Mid(myStr, i, 1)
If Asc(myTemp) > 57 Or Asc(myTemp) < 48 Then
myStr = Replace(myStr, myTemp, " ")
End If
Next
myOutput = Split(myStr, " ")
For i = 0 To UBound(myOutput)
If myOutput(i) <>