2个回答
展开全部
Private Sub Command1_Click()
Dim str As String, strTmp As String, intN As Integer, intM As Integer
Dim intX As Integer, intY As Integer, intZ As Integer, intW As Integer
str = Text1.Text
intN = Len(str)
For intM = 1 To intN
strTmp = UCase(Mid(str, intM, 1))
If IsNumeric(strTmp) Then '数字
intX = intX + 1
ElseIf Asc(strTmp) > 64 And Asc(strTmp) < 91 Then '字母
intY = intY + 1
ElseIf strTmp = " " Then '空格
intZ = intZ + 1
Else '其它
intW = intW + 1
End If
Next
Text2.Text = "数字个数为:" & intX
Text3.Text = "字母个数为:" & intY
Text4.Text = "空格个数为:" & intZ
Text5.Text = "特殊字符个数为:" & intW
End Sub
'如果满意我的回答,请采纳.谢谢
Dim str As String, strTmp As String, intN As Integer, intM As Integer
Dim intX As Integer, intY As Integer, intZ As Integer, intW As Integer
str = Text1.Text
intN = Len(str)
For intM = 1 To intN
strTmp = UCase(Mid(str, intM, 1))
If IsNumeric(strTmp) Then '数字
intX = intX + 1
ElseIf Asc(strTmp) > 64 And Asc(strTmp) < 91 Then '字母
intY = intY + 1
ElseIf strTmp = " " Then '空格
intZ = intZ + 1
Else '其它
intW = intW + 1
End If
Next
Text2.Text = "数字个数为:" & intX
Text3.Text = "字母个数为:" & intY
Text4.Text = "空格个数为:" & intZ
Text5.Text = "特殊字符个数为:" & intW
End Sub
'如果满意我的回答,请采纳.谢谢
展开全部
'写错了 我改了下
function stABC(word)'字母个数
Abc="abcdefghijklmnopqrstuvwxyz" '所有的字母都是小写的啊
word=lcase(word)'小写所有的字母我自己用小写的来判断的
for i=1 to len(word)
if instr(abc,mid(word,i,1))>0 then '找到了当然就+1了
t=t+1
end if
next
stABC=t '返回找到的字母数
end function
'统计数字
function stNo(word)
no="0123456789" '
for i=1 to len(word)
if instr(no,mid(word,i,1))>0 then '找到了当然就+1了
t=t+1
end if
next
stNo=t '返回找到的数
end function
'统计空格
function stSp(word)
l1=len(word)
l2=len(replace(word," ",""))'把空格全替换了再求长
stSp=l1-l2 '-下就是我们空格数了
end function
function lenNo(word)
lenNo=len(word)
end function
'下面开始使用了
tword=inputbox("输入要统计的字符吧!")
showWord="字母个数为:"&stabc(tword)
showword=showword+"数字个数为:" &stno(tword)
showword=showword+"空格个数为:" &stsp(tword)
showword=showword+"长度为:" &lenno(tword)
msgbox(showword)
function stABC(word)'字母个数
Abc="abcdefghijklmnopqrstuvwxyz" '所有的字母都是小写的啊
word=lcase(word)'小写所有的字母我自己用小写的来判断的
for i=1 to len(word)
if instr(abc,mid(word,i,1))>0 then '找到了当然就+1了
t=t+1
end if
next
stABC=t '返回找到的字母数
end function
'统计数字
function stNo(word)
no="0123456789" '
for i=1 to len(word)
if instr(no,mid(word,i,1))>0 then '找到了当然就+1了
t=t+1
end if
next
stNo=t '返回找到的数
end function
'统计空格
function stSp(word)
l1=len(word)
l2=len(replace(word," ",""))'把空格全替换了再求长
stSp=l1-l2 '-下就是我们空格数了
end function
function lenNo(word)
lenNo=len(word)
end function
'下面开始使用了
tword=inputbox("输入要统计的字符吧!")
showWord="字母个数为:"&stabc(tword)
showword=showword+"数字个数为:" &stno(tword)
showword=showword+"空格个数为:" &stsp(tword)
showword=showword+"长度为:" &lenno(tword)
msgbox(showword)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询