2 Replies Latest reply on Jul 22, 2013 1:06 PM by LaRetta_1

    Middle Function

    cschul

      Title

      Middle Function

      Post

           I'm having some difficulty extracting selected text from a text field and put it into it's own field. So for example, I have a paragraph of text and I need to be able to search for a phrase. Melting Point: 50C. So I figured to first search for the word melting and end with the first C that it finds and everything between. 

           I tried the custom function below from http://www.briandunning.com/cf/644

            

           /*
           Between ( text ; searchString1 ; occurrence1 ; include1_1 ; searchString2 ; occurrence2 ; include2_1)
            
           by Fabrice Nordmann
           v.2, Mar 2007
           v.1, Jan 2007
            
           v.2 adds inclusion boolean parameters
            
           extracts the middle of a text in between delimiters, based on a search strings and an occurrence numbers
           occurrences can be positive (starting from the beginning of the text) or negative (starting from the end)
            
           see also Before After, and BetweenNext functions
           */
           Let ([
             _occurrence1 = Case ( occurrence1 = 0 ; 1 ; occurrence1 )
           ; _occurrence2 = Case ( occurrence2 = 0 ; 1 ; occurrence2 )
           ; _p1= Position ( text ; searchString1 ; Case ( _occurrence1 < 0 ; Length ( text ) ; 1 ) ; _occurrence1 ) + not GetAsBoolean ( include1_1 ) * Length ( searchString1 )
           ; _p2= Position ( text ; searchString2 ; Case ( _occurrence2 < 0 ; Length ( text ) ; 1 ) ; _occurrence2 ) + GetAsBoolean ( include2_1 ) * Length ( searchString2 )
            
           ]
           ;
           Middle ( text ; _p1 ; _p2 - _p1 )
           )
            

        • 1. Re: Middle Function
          philmodjunk

               And what "incorrect" results do you get when you try to use that function?

               What does the text look like from which you are parsing that data?

          • 2. Re: Middle Function
            LaRetta_1

                 If you have a paragraph and you have a global Extract text field in which you place the text you wish to begin with, then this will easily select the first word past your text as:

                  

                 Let ( [
                 start = Position ( paragraph ; extract ; 1 ; 1 ) + Length ( extract ) ;
                 remainder = Right ( paragraph ; Length ( paragraph ) - start )
                 ] ;
                 LeftWords ( remainder ; 1 )
                 )
                  
                 So in this situation, if you type Melting Point: ... it will find 50C.  And if you type Melting, it will find Point.