finding specific text in textarea

Hi,

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.

Michael

InStr? RegEx?

x=Instr(myTextArea.text,"WhatToLookFor")

use SelStart and SelLength if you want to highlight the found text

thanks, will try this.

InStr makes an integer from a string, or? Makes this sense?

Where do i find SelStart and SelLenght?

I’m on Windows.

SelStart and SelLength are available only in controls taking some text content.

If you want to analyze a string outside that scope, you will need to restrict to Left, Mid, Right… but they are really efficient too.

try the Language Ref documents, it is all explained there…

them come back if you don’t understand

The OP specified TEXTAREA

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 :smiley:

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)

[quote=441167:@Dave S]try the Language Ref documents, it is all explained there…

them come back if you don’t understand

The OP specified TEXTAREA[/quote]

got it:

[code]dim findFirst As integer = InStr(TextArea_cURLOutput.Text, “datacenters/”)

TextArea_cURLOutput.SelStart = findFirst + 11
TextArea_cURLOutput.SelLength = 36
txt_DatacenterID.Text = TextArea_cURLOutput.SelText[/code]

thanks
Michael