输入一串字符统计其中某字母个数vb
2个回答
展开全部
Private Sub Command1_Click()
s = Text1.Text
For i = 1 To Len(s)
If Mid(s, i, 1) = "A" Or Mid(s, i, 1) = "a" Then
na = na + 1
Else
If Mid(s, i, 1) = "E" Or Mid(s, i, 1) = "e" Then
ne = ne + 1
Else
If Mid(s, i, 1) = "Z" Or Mid(s, i, 1) = "z" Then
nz = nz + 1
End If
End If
End If
Next i
Print "Na="; na, "Ne="; ne, "Nz="; nz
End Sub
展开全部
's : 字符串
'c : 指定的字符
Public Function CharCount(ByVal s As String, ByVal c As String) As Integer
Dim i As Integer, count As Integer
i = 1
count = 0
Do While (i <= Len(s))
If (Mid(s, i, 1) = c) Then count = count + 1
i = i + 1
Loop
CharCount = count
End Function
'调用
Dim count as Integer
count =CharCount("AAABBEEEZZCCC", "A")
'结果:count = 3
count =CharCount("AAABBEEEEEZZCCC", "E")
'结果:count=5
count =CharCount("AAABBEEEEEZZCCC", "Z")
'结果:count=2
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询