VBA程序编写:输入一串字符,统计字符串中英文字母,数字,空格和其他字符的个数
1个回答
展开全部
Sub mm()
Dim strn$, i&, n&, chrs(1 To 4) As Integer, strr
strr = Array("空格数量", "数字数量", "英文字母数量", "其他字符数量")
strn$ = InputBox("输入字符串:", "输入", "1")
n = Len(strn)
For i = 1 To n
Select Case Mid(strn, i, 1)
Case " "
chrs(1) = chrs(1) + 1 '空格数量
Case "0" To "9"
chrs(2) = chrs(2) + 1 '数字数量
Case "A" To "Z", "a" To "z"
chrs(3) = chrs(3) + 1 '英文字母数量
Case Else
chrs(4) = chrs(4) + 1 '其他字符数量
End Select
Next i
For i = 1 To 4
strn = strn & Chr(10) & chrs(i) & ":" & strr(i - 1)
Next i
MsgBox strn, vbOKOnly
End Sub
Dim strn$, i&, n&, chrs(1 To 4) As Integer, strr
strr = Array("空格数量", "数字数量", "英文字母数量", "其他字符数量")
strn$ = InputBox("输入字符串:", "输入", "1")
n = Len(strn)
For i = 1 To n
Select Case Mid(strn, i, 1)
Case " "
chrs(1) = chrs(1) + 1 '空格数量
Case "0" To "9"
chrs(2) = chrs(2) + 1 '数字数量
Case "A" To "Z", "a" To "z"
chrs(3) = chrs(3) + 1 '英文字母数量
Case Else
chrs(4) = chrs(4) + 1 '其他字符数量
End Select
Next i
For i = 1 To 4
strn = strn & Chr(10) & chrs(i) & ":" & strr(i - 1)
Next i
MsgBox strn, vbOKOnly
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询