急!用VB编写程序,对输入的字符串进行识别,找出其中大写字母、小写字母、空格、数字及其他字符的个数。 10
4个回答
展开全部
Option Explicit
'在窗体中添一个CommandButton、一个TextBox
Private Sub Command1_Click()
Dim IntL As Long, IntU As Long, IntS As Long, IntN As Long, IntO As Long
Dim I As Long, Char As String * 1
For I = 1 To Len(Text1.Text)
Char = Mid(Text1.Text, I, 1)
Select Case Char
Case "A" To "Z": IntU = IntU + 1
Case "a" To "z": IntL = IntL + 1
Case "0" To "9": IntN = IntN + 1
Case " ": IntS = IntS + 1
Case Else: IntO = IntO + 1
End Select
Next
MsgBox "TextBox中的字符串统计结果:" & vbCrLf & Space(2) & "大写字母:" & IntU & "个" _
& vbCrLf & Space(2) & "小写字母:" & IntL & "个" _
& vbCrLf & Space(2) & "数字:" & IntN & "个" _
& vbCrLf & Space(2) & "空格:" & IntS & "个" _
& vbCrLf & Space(2) & "其它字符:" & IntO & "个", vbOKOnly Or vbInformation, "统计字符输出"
End Sub
'在窗体中添一个CommandButton、一个TextBox
Private Sub Command1_Click()
Dim IntL As Long, IntU As Long, IntS As Long, IntN As Long, IntO As Long
Dim I As Long, Char As String * 1
For I = 1 To Len(Text1.Text)
Char = Mid(Text1.Text, I, 1)
Select Case Char
Case "A" To "Z": IntU = IntU + 1
Case "a" To "z": IntL = IntL + 1
Case "0" To "9": IntN = IntN + 1
Case " ": IntS = IntS + 1
Case Else: IntO = IntO + 1
End Select
Next
MsgBox "TextBox中的字符串统计结果:" & vbCrLf & Space(2) & "大写字母:" & IntU & "个" _
& vbCrLf & Space(2) & "小写字母:" & IntL & "个" _
& vbCrLf & Space(2) & "数字:" & IntN & "个" _
& vbCrLf & Space(2) & "空格:" & IntS & "个" _
& vbCrLf & Space(2) & "其它字符:" & IntO & "个", vbOKOnly Or vbInformation, "统计字符输出"
End Sub
展开全部
遍历字符串,比较其ASCII,分别用不同的变量
参考代码
Dim intNumber As Integer, intUcase As Integer, intLcase As Integer, intSpace As Integer
Dim i As Integer, strTmp As String
intNumber = 0
intUcase = 0
intLcase = 0
intSpace = 0
For i = 1 To Len(Text1.Text)
strTmp = Mid(Text1.Text, i, 1)
If Asc(strTmp) > 47 And Asc(strTmp) < 58 Then intNumber = intNumber + 1
If Asc(strTmp) > 64 And Asc(strTmp) < 91 Then intUcase = intUcase + 1 '大写字母个数
If Asc(strTmp) > 96 And Asc(strTmp) < 123 Then intLcase = intLcase + 1
If Asc(strTmp) = 32 Then intSpace = intSpace + 1
Next
参考代码
Dim intNumber As Integer, intUcase As Integer, intLcase As Integer, intSpace As Integer
Dim i As Integer, strTmp As String
intNumber = 0
intUcase = 0
intLcase = 0
intSpace = 0
For i = 1 To Len(Text1.Text)
strTmp = Mid(Text1.Text, i, 1)
If Asc(strTmp) > 47 And Asc(strTmp) < 58 Then intNumber = intNumber + 1
If Asc(strTmp) > 64 And Asc(strTmp) < 91 Then intUcase = intUcase + 1 '大写字母个数
If Asc(strTmp) > 96 And Asc(strTmp) < 123 Then intLcase = intLcase + 1
If Asc(strTmp) = 32 Then intSpace = intSpace + 1
Next
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以把字符遍历一下,然后用ASCII值来判断统计,具体函数请参考MSDN。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我怎么觉得我前几天回答了这个问题呀!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询