2 Replies Latest reply: May 15, 2014 10:04 AM by drobert _ RSS

    Explanation of Extract() function

    drobert _

      Hi all. I have a little problem understanding why my extract function does not behave the way it is supposed to (or the way I expected it to).

       

      The following is the function I am using which is used in the calculated character field defined as a length of 6 (Messages is the fields that is defined in my Append trap that contains the whole line):

      Trim( Extract(( Messages )), "REF#" )[/SIZE][/code]

       

      The function works fine when I have the following:

                                                 REF#    380                                                                            /code

      The result is "380" as expected.

       

      but does not work with the following:

                                                 REF#   1629 TERM ID 0819;      00001           CARD #    2                         /code

      The result is "1629 T" which is not correct and obviously is picking up the next field.

       

      If I add " " as the Ending point, nothing shows up for any scenario. I cannot use an ending value as the REF# can be almost anywhere on the line.

       

      Can anyone point me in the right direction as to how to use this function?:confused:

        • Explanation of Extract() function
          Grant Perkins

          Hi all. I have a little problem understanding why my extract function does not behave the way it is supposed to (or the way I expected it to).

           

          The following is the function I am using which is used in the calculated character field defined as a length of 6 (Messages is the fields that is defined in my Append trap that contains the whole line):

          Trim( Extract(( Messages )), "REF#" )[/SIZE][/code]

          /quote

           

          Surely ....

           

          Trim( Extract( , "REF#" ))[/SIZE][/code]

           

          ??[/SIZE]

           

          So Extract will take the "REF#" out of the picture, TRIM will remove leading spaces and then you will get the next 6 characters (per the field size.)[/SIZE]

           

          Therefore that would be 3 digits followed by 3 spaces in your first example and 4 digits followed by one space and then the letter T in your second example.[/SIZE]

           

          If you just want the digits you will need to LSPLIT as well.[/SIZE]

          [/SIZE]

          LSPLIT(/SIZE[SIZE=2][SIZE=2]Trim( Extract( , "REF#" )),2," ",1)[/SIZE][/SIZE]

           

          [SIZE=2]should do it.[/SIZE]

           

           

          HTH,[/SIZE]

           

           

          Grant[/SIZE]

           

           

          ETA: In V10 using the intrim function with LSPLIT you could do something like:

           

          LSPLIT(INTRIM(Messages),3," ",2)[/code]

           

          to give the same result.

           

           

          /SIZE

            • Explanation of Extract() function
              drobert _

              Surely ....

               

              Trim( Extract( , "REF#" ))[/SIZE][/code]

               

              ??[/SIZE]

              /quote

              Oops, that what I meant...:o that's what happens when you type it in instead of cuting and pasting the formula.

               

              So Extract will take the "REF#" out of the picture, TRIM will remove leading spaces and then you will get the next 6 characters (per the field size.)[/SIZE]

               

              Therefore that would be 3 digits followed by 3 spaces in your first example and 4 digits followed by one space and then the letter T in your second example.[/SIZE]

               

              If you just want the digits you will need to LSPLIT as well.[/SIZE]

               

              LSPLIT(/SIZE[SIZE=2][SIZE=2]Trim( Extract( , "REF#" )),2," ",1)[/SIZE][/SIZE]

               

              [SIZE=2]should do it.[/SIZE]

              /SIZE[/quote]

              I guess I misunderstood its functionality... I thought that it functioned just like the split functions where one would give it a starting delimeter instead of a relative position. I see now that it acts more like a substr function. It all makes sense now!:rolleyes:

               

              Thanks again for your help Grant.