2 Replies Latest reply on Nov 30, 2011 7:36 PM by kbda

    Calculation to return a word after a search string

    kbda

      Title

      Calculation to return a word after a search string

      Post

      This should be simple but I can't seem to figure it out: I want to make a calculation which returns the word which follows a specific text. For example my text field called "email" contains (amongst other things)  firstname = Katherine, and I want to be able to make a calculation which will return "Katherine" after I specify that I want the word after the text string "firstname =" I think this should probably be achievable with the "position" text function, combined with a RightWord function, but I can't make it work. 

      I'd appreciate any help, tips... Thanks!

        • 1. Re: Calculation to return a word after a search string
          LaRetta_1

          Two calculations come to mind, where gSearch is a global to hold your "firstname=" search string and 'text' is the name of your text string you are searching:

          Let ( [
          len = Length ( gSearch ) ;
          pos = Position ( text ; gSearch ; 1 ; 1 )
          ] ;
          Case ( pos ; LeftWords ( GetValue ( Replace ( text ; pos + len  ; 0 ; ¶ ) ; 2 ) ; 1 ) )
          )

          OR

          Let ( [
          len = Length ( gSearch ) ;
          pos = Position ( text ; gSearch  ; 1 ; 1 )
          ] ;
          Case ( pos ; LeftWords ( Right ( text ; Length ( text ) - pos - len ) ; 1 ) )
          )

          Note that normally, one would use Trim() to remove any errant spaces but it is not required here since LeftWords() and RightWords() always drop any word-break characters such as carriage returns and spaces.

          • 2. Re: Calculation to return a word after a search string
            kbda

            I'm so sorry, but I still don't quite get it. Do I have to set up a global field (called gSearch) in my database with the value specified as "firstname = "? When I tried that, I couldn't set up the calculation because it said the TABLE "gSearch" couldn't be found. 

            Thank you so much for your time and thoughts, there's no way I could have come up with the calculations you wrote above.