VB程序:统计子字符串在原字符串中出现的次数

来源:百度知道 编辑:UC知道 时间:2024/06/20 12:07:11
弄下代码、谢谢~

Private Sub Command1_Click()
If Len(Text1.Text) = 0 Then
MsgBox "请输入原字符串内容:"
Text1.SetFocus
ElseIf Len(Text2.Text) = 0 Then
MsgBox "请输入子字符串内容:"
Text2.SetFocus
Else
Label3.Caption = "子字符串在原字符串中出现了:" & UBound(Split(Text1.Text, Text2.Text)) & "次"
End If
End Sub

s1=Text1.Text
s2=Text2.Text
msgbox "出现了:" & (len(s1)-len(replace(s1,s2,"")))/len(s2)