Searching Backwards in textarea

  1. 7 months ago

    Steve K

    29 Nov 2019 Testers, Xojo Pro

    I have found a way to search forwards (or down) in a textarea but I'm having trouble searching backwards (or up).

    Here is what I have for forwards (or down):

    Var searchText As String = tfFindUp.Value
    Var charPos As Integer
    Var startPosition as Integer
    if taMain.SelectionLength > 0 then
      startPosition = taMain.SelectionStart  + 1
      startPosition = 0
    charPos = taMain.Value.IndexOf(startPosition, searchText)
    If charPos >= 0 Then
      taMain.SelectionStart = charPos
      taMain.SelectionLength = searchText.Length
    End If

    Can anyone help me figure out how to search backwards?
    By default Indexof only works moving forward. I was thinking of looping one character at a time backwards (-1) until it found the next. I also thought of reversing the text area in memory, but that was way too messy.

    Any thoughts?

  2. Beatrix W

    29 Nov 2019 Testers, Third Party Store Europe (Germany)

    Invert the string first?

  3. Emile S

    29 Nov 2019 Europe (France, Strasbourg)

    What are you really searching ?

    From the end of the document back to the start, are-you searching the word Var or raV ?

  4. Jean-Yves P

    29 Nov 2019 Testers, Xojo Pro Europe (France, Besançon)

    search for all the found text selstart and sellength, and store them in an array
    then you can go easily forward or backward in the array of the results.

or Sign Up to reply!