4个回答
展开全部
这段程序在歌词中找“you”,运行结果是2
A = "爱你就说I love you,想你就上ICQ(I seek you)..."
B = "you"
C = 1
D = 0
'AB不解释了,C是查找的起点,D是统计出现次数
Do
C = InStr(C, A, B) '第1次从1开始找,找到you位置在12,结果C=12(第2次就从15开始找)
If C > 0 Then D = D + 1: C = C + Len(B) '如果找到了,加1次:下次向后跳3格找(因为you是3个字母)
Loop Until C = 0 '如果找不到,循环结束
MsgBox D
A = "爱你就说I love you,想你就上ICQ(I seek you)..."
B = "you"
C = 1
D = 0
'AB不解释了,C是查找的起点,D是统计出现次数
Do
C = InStr(C, A, B) '第1次从1开始找,找到you位置在12,结果C=12(第2次就从15开始找)
If C > 0 Then D = D + 1: C = C + Len(B) '如果找到了,加1次:下次向后跳3格找(因为you是3个字母)
Loop Until C = 0 '如果找不到,循环结束
MsgBox D
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一个文本框text1,一个命令按钮command1
绝对好
Private Sub command1_Click()
Dim search2 As String, start&, Num&, a#, Zifushu1%, Zifushu2#, searchInwhere$
search2 = InputBox(Chr(10) & Chr(10) & Chr(10) & Chr(10) & " 统计内容")
start = 1: Num = 0: Zifushu1 = Len(search2): searchInwhere = Text1.Text: Zifushu2 = Len(searchInwhere)
If search2 <> "" Then
Do While start <= Zifushu2
If search2 = Mid$(searchInwhere, start, Zifushu1) Then Num = Num + 1
start = start + 1
Loop
MsgBox "共找到" & Num & "个" & "'" & search2 & "'", vbOKOnly + vbInformation
End If
End Sub
绝对好
Private Sub command1_Click()
Dim search2 As String, start&, Num&, a#, Zifushu1%, Zifushu2#, searchInwhere$
search2 = InputBox(Chr(10) & Chr(10) & Chr(10) & Chr(10) & " 统计内容")
start = 1: Num = 0: Zifushu1 = Len(search2): searchInwhere = Text1.Text: Zifushu2 = Len(searchInwhere)
If search2 <> "" Then
Do While start <= Zifushu2
If search2 = Mid$(searchInwhere, start, Zifushu1) Then Num = Num + 1
start = start + 1
Loop
MsgBox "共找到" & Num & "个" & "'" & search2 & "'", vbOKOnly + vbInformation
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Function strCount(strA As String, strB As String) As Long
Dim lngA As Long
Dim lngB As Long
Dim lngC As Long
lngA = Len(strA)
lngB = Len(strB)
lngC = Len(Replace(strA, strB, ""))
strCount = (lngA - lngC) / lngB
MsgBox strCount
End Function
Dim lngA As Long
Dim lngB As Long
Dim lngC As Long
lngA = Len(strA)
lngB = Len(strB)
lngC = Len(Replace(strA, strB, ""))
strCount = (lngA - lngC) / lngB
MsgBox strCount
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询