7,785
社区成员




Option Explicit
Private Sub Command1_Click()
'计算selStr在Str中出现的次数
Dim Str As String, selStr As String
Dim Arr() As String
Str = Text1.Text
selStr = Text3.Text
Arr = Split(Str, selStr)
Text4.Text = UBound(Arr)
End Sub
Private Sub Form_Load()
Text1.Text = "exTextTextTextTextTextTextTextTextTextTextex"
Text3.Text = "ex"
Text4.Text = ""
End Sub
Dim str As String
Dim col As String
Dim pos1, pos2, count As Single
str = Me.Text1.Text
col = Me.Text2.Text
count = 0
pos1 = 1
Do While pos1 > 0
pos2 = InStr(pos1, str, col)
If pos2 = 0 Then
Exit Do
Else
count = count + 1
End If
pos1 = pos2 + Len(col)
Loop
Me.Text3.Text = count
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str, col As String
Dim st() As String
col = Me.TextBox2.Text.ToString.Trim '要查找的字符串
str = Me.TextBox1.Text.ToString.Trim '原始文本字符串
st = str.Split(col)
Me.TextBox3.Text = st.Length - 1 '字符串出现的次数
End Sub
Option Explicit
Private Sub Command1_Click()
Dim Pos1 As Single, Pos2 As Single, Count As Single, Str As String, selStr As String
Str = Text1.Text
selStr = Text3.Text
Pos1 = 1
Count = 0
Do While True
Pos2 = InStr(Pos1, Str, selStr)
If Pos2 = 0 Then
Exit Do Else
Count = Count + 1
End If
Pos1 = Pos2 + Len(selStr)
Loop
Text4.Text = Count
End Sub