VB中统计大小写字母及数字个数代码怎么写

2025-02-24 23:19:47
推荐回答(2个)
回答1:

Dim str1 As String
Dim i As Long, n As Long
Dim c1 As Long, c2 As Long, c3 As Long '数字、小写字母、大写字母
c1 = 0: c2 = 0: c3 = 0
str1 = Text1.Text
For i = 1 To Len(str1)
n = Asc(Mid(str1, i, 1))
Select Case n
Case 48 To 57 '数字0-9
c1 = c1 + 1
Case 97 To 122 '小写字母 a-z
c2 = c2 + 1
Case 65 To 90 '大写字母 A-Z
c3 = c3 + 1
Case Else
End Select
Next i
MsgBox "数字:" & c3 & vbCrLf & "小写字母:" & c2 & vbCrLf & "大写字母:" & c3

回答2:

Private Sub Command1_Click()
Dim a As String,dx As Integer
Dim xx As Integer,sz As Integer
a = "ASDFasdfASDFYZ0123asdfyz456789"
For i = 1 To Len(a)
Select Case Mid(a,i,1)
Case "0" To "9"
sz = sz + 1
Case "A" To "Z"
dx = dx + 1
Case "a" To "z"
xx = xx + 1
End Select
Next
MsgBox "大写" & dx & "小写" & xx & "数字" & sz
End Sub