VB 怎样统计Text中某个字符个数
答案:3 悬赏:70 手机版
解决时间 2021-11-09 13:43
- 提问者网友:贪了杯
- 2021-11-08 16:26
VB 怎样统计Text中某个字符个数
最佳答案
- 五星知识达人网友:十年萤火照君眠
- 2021-11-08 17:21
统计某个字符的代码如下:
Private Sub Command1_Click()
Dim i As Integer, Ccount As Integer
For i = 1 To Len(Text1)
If Mid(Text1, i, 1) = "你所需要统计的字符" Then Ccount = Ccount + 1
Next i
msgbox "共有" & Count & "个e"
End Sub
Private Sub Command1_Click()
Dim i As Integer, Ccount As Integer
For i = 1 To Len(Text1)
If Mid(Text1, i, 1) = "你所需要统计的字符" Then Ccount = Ccount + 1
Next i
msgbox "共有" & Count & "个e"
End Sub
全部回答
- 1楼网友:过活
- 2021-11-08 20:16
统计字符个数
text2=len(text1)-len(replace(text1,"*",""))
要统计个数可以用len函数,在文本框的change事件里面写代码。
text2=len(text1)-len(replace(text1,"*",""))
要统计个数可以用len函数,在文本框的change事件里面写代码。
- 2楼网友:等灯
- 2021-11-08 18:59
假如你的文本框是text1,label是label1
Private Sub Text1_Change()
Dim i As Long
Dim s As Long
s = 0
For i = 1 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) = "*" Then s = s + 1
Next i
Label1.Caption = s
End Sub
Private Sub Text1_Change()
Dim i As Long
Dim s As Long
s = 0
For i = 1 To Len(Text1.Text)
If Mid(Text1.Text, i, 1) = "*" Then s = s + 1
Next i
Label1.Caption = s
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯