2个文本框,1个标签框,1个按钮
乱写的:
Private Sub Command1_Click()
Dim StrNum, LenStr As Integer
Dim OneStr, TwoStr, NumBer As Integer
'获取主字符串字符个数
NumBer = Len(Text1.Text)
'获取子字符串在主子字符串中的位置
StrNum = InStr(Text1.Text, Text2.Text)
'获取子字符串的字符个数
LenStr = Len(Text2.Text)
If StrNum <> 0 Then
'将在主字符串中出现第一子字符串删除,形成一个新串在标签框中显出来
'
'获取子字符串在主字符串前面的字符
OneStr = Mid(Text1.Text, 1, StrNum - 1)
'获取子字符串在主字符串后面的字符
TwoStr = Right(Text1.Text, NumBer - (StrNum + LenStr - 1))
Label1.Caption = OneStr & TwoStr
Else
'从主字符串右边取出与子字符串个数相同的字符串在标签框中显示出来
Label1.Caption = Right(Text1.Text, LenStr)
End If
End Sub
Private Sub Form_Load()
Text1.Text = "主字符串"
Text2.Text = "子字符串"
Command1.Caption = "确定"
Label1.Caption = "这里显示结果"
Label1.Top = 0
Label1.Left = 525
Label1.Alignment = 2
Label1.Height = 450
Label1.Width = 3600
Text1.Top = Label1.Height
Text1.Left = 525
Text1.Height = 1050
Text1.Width = 3600
Text2.Top = Text1.Height + Label1.Height + 100
Text2.Left = 525
Text2.Height = 375
Text2.Width = 3600
Command1.Top = Text1.Height + Label1.Height + Text2.Height + 200
Command1.Left = 1600
End Sub