i’m back to Xojo after a few years… so sorry for my basic questions:
How can i find a specific text within a textarea and maybe get the next few characters after this string:
iamastring: iamanotherstring (there are a lot more characters in the textarea)
How do i get iamanotherstring? I have to find iamastring first, because this is a known string, iamanotherstring is dynamic, so i cannot search directly for it.
There are soooo many ways to do it. I want to show another way of doing it with RegEx.
Create a Module and Paste the following Text into Xojo while you have selected the Module in the Navigator:
[code]Public Function GetWordAfter(Extends s As String, WordBeforeTheWord As String) as String
Dim rx As New RegEx
rx.SearchPattern = “(?Umi-s)” + WordBeforeTheWord + “(.+)\s”
Dim rxOptions As RegExOptions = rx.Options
rxOptions.LineEndType = 4
Dim match As RegExMatch = rx.Search( s)
If match <> Nil Then
If match.SubExpressionCount > 0 Then
Return match.SubExpressionString(1) // Add .Trimm if you want to strip the spaces before and after the found word
End If
End If
End Function
[/code]
This will extends any String with a new Method called “GetWordAfter”. This Method needs the Word to look for and delivers back the word after this word. So you can examine any String and look for a String after a String
Like this MsgBox Me.Text.GetWordAfter("iamastring")
But be carefull. I t may fail if you have special chars in your search.
BTW: The Code has been made with the help of RegExRX (macOS)