用退格键,删除键整体清除文本框中某一字符串

只删除<#>mn<#>形式的,而且是一个一个地删,比如有信息"<#>m01<#><#>m02<#><#>m03<#>backspace"按退格键的时候,先删除e,然后挨个删除,到了<#>m03<#>,将它整个删除,接着<#>m02<#>,最后<#>m01<#>

Private Sub Text1_Keydown(KeyCode As Integer, Shift As Integer)
Dim s, tmp
s = Text1.SelStart + 1: tmp = Text1
If KeyCode = 8 Then
    If s < 9 Then Exit Sub
    If Mid(tmp, s - 9, 9) Like "<[#]>m##<[#]>" Then
        tmp = Left(tmp, s - 9) & Mid(tmp, s)
        Text1 = tmp: Text1.SelStart = s - 9
    End If
ElseIf KeyCode = 46 Then
    If s + 8 > Len(tmp) Then Exit Sub
    If Mid(tmp, s, 9) Like "<[#]>m##<[#]>" Then
        tmp = Left(tmp, s - 1) & Mid(tmp, s + 8)
        Text1 = tmp: Text1.SelStart = s - 1
    End If
End If
End Sub

你可能感兴趣的:(用退格键,删除键整体清除文本框中某一字符串)