vb编程,输入一个字符串,分别统计其中有多少个字母、多少个数字、多少个其他字符
展开全部
'每次读一个字符,转换成大写后,用ascii码判断
Private Sub Command1_Click()
Dim n1 As Integer, n2 As Integer, n3 As Integer
Dim s1 As String, s2 As String, s3 As String
For i = 1 To Len(Text1.Text)
Select Case Asc(UCase(Mid(Text1.Text, i, 1)))
Case 48 To 57 '数字
n1 = n1 + 1
s1 = s1 & Mid(Text1.Text, i, 1)
Case 65 To 90 '字母
n2 = n2 + 1
s2 = s2 & Mid(Text1.Text, i, 1)
Case Else '其它字符
n3 = n3 + 1
s3 = s3 & Mid(Text1.Text, i, 1)
End Select
Next i
Print s1, "数字个数="; n1
Print s2, "字母个数="; n2
Print s3, "其它字符个数="; n3
End Sub
Private Sub Command1_Click()
Dim n1 As Integer, n2 As Integer, n3 As Integer
Dim s1 As String, s2 As String, s3 As String
For i = 1 To Len(Text1.Text)
Select Case Asc(UCase(Mid(Text1.Text, i, 1)))
Case 48 To 57 '数字
n1 = n1 + 1
s1 = s1 & Mid(Text1.Text, i, 1)
Case 65 To 90 '字母
n2 = n2 + 1
s2 = s2 & Mid(Text1.Text, i, 1)
Case Else '其它字符
n3 = n3 + 1
s3 = s3 & Mid(Text1.Text, i, 1)
End Select
Next i
Print s1, "数字个数="; n1
Print s2, "字母个数="; n2
Print s3, "其它字符个数="; n3
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询