If I understand correctly, wouldn't the quickest way be to use the InstrRev() function since you're searching from the end of the text (last message from *priv* bot)?
Like this (didn't test it):
Code:Option Explicit Private Sub Form_Load() 'Use it like: Dim strBot As String strBot = LastBotSpeak(Text1.Text) End Sub Private Function LastBotSpeak(ByRef Text As String) As String Dim lonStart As Long, lonSLen As Long Dim lonEnd As Long lonStart = InStrRev(Text, "*priv* skill.bot:") lonSLen = 17 'Length of *priv* skill.bot: If lonStart > 0 Then lonStart = lonStart + lonSLen lonEnd = InStr(lonStart, Text, vbCrLf) If lonEnd > 0 Then LastBotSpeak = Mid$(Text, lonStart, lonEnd - lonStart) End If End If End Function




Reply With Quote