I use the following VB6 code to Ctrl+Backspace words, but it only works if the words are separated by spaces. I need it to work if the words are separated by any special character: . - #, etc.
Public Sub DelLastWord(tb As TextBox)
Dim WordStart As String
Dim Trimmed As String
Dim curpos As Long
curpos = tb.SelStart
Trimmed = Trim$(Left$(tb.Text, curpos))
If LenB(Trimmed) Then
WordStart = InStrRev(Trimmed, Space$(1), Len(Trimmed))
tb.SelStart = WordStart
tb.SelLength = curpos - WordStart
tb.SelText = vbNullString
End If
End Sub
Any suggestions or code someone can give me to take care of special characters?
I would loop backwards from the insertion point until I found a separator character. Something like this: