Searching Backwards in textarea

  1. 2 weeks ago

    Steve K

    Nov 29 Pre-Release 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
    else
      startPosition = 0
    end
    
    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

    Nov 29 Pre-Release Testers, Third Party Store Europe (Germany)

    Invert the string first?

  3. Emile S

    Nov 29 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

    Nov 29 Pre-Release 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!