程序界面如下图所示,程序运行时,在文本框Text1中输入一段文本,在文本框Text2中输入查找的字符串,在文本框Text3中输入替换为的字符串,单击“查找替换”按钮Command1,则在文本框Text4中输出替换后的文本,在标签Label6中显示替换的次数。
实现上述功能的VB程序如下,请在程序划线处填入合适的代码。
Private Sub Command1_Click()
Dim st1 As String, st2 As String
Dim i As Integer, n As Integer, count As Integer
Dim st3 As String, ch As String, result As String
result = “ ”
st1 = Text1.Text
st2 = Text2.Text
st3 = Text3.Text
len1 = Len(Text2.Text)
result = “ ”
i = 1
Do While i <= n
If ch = st2 Then
result = result + st3
count = count + 1
i = i + len1
Else
i = i + 1
End If
Loop
Text4.Text = result
Label6.Caption = Str(count)
End Sub