用vb怎样统计文本框内有多少个"p"字符?

2025-04-05 22:55:28
推荐回答(2个)
回答1:

Dim s As String
Dim i As Long
Dim count As Long

s = Text1.Text
'如果不区分大小写加上这句
's = LCase$(s)
For i = 1 To Len(s)
If Mid$(s, i, 1) = "p" Then count = count + 1
Next i
Print count

回答2:

给你个我刚写的函数,调用方式会吧。Str参数为要统计的字符串

Function TjChr(Str As String) As Integer
Dim i As Integer, sum As Integer
For i = 1 To Len(Str)
If Mid(Str, i, 1) = "p" Then sum = sum + 1
Next i
TjChr = sum
End Function