2 Replies Latest reply on Nov 24, 2016 7:18 PM by David Moyer

    Another custom function for text parsing

    David Moyer

      Hi all,

      This is just an update/improvement on a previous post.  I wanted to create a document because of the HUGE demand for this.

      A recent example of usage:

      $parsedURL =  ParseValueByBookends ( $resultHTML; "href=\""; 2; "\">" )

      This would extract the second occurrence of a href url from the text.

      Capture.PNG

      Let(

        [

          posL = Position(text; leftSideTag; 1; occurrence);

          posR = Position(text; rightSideTag; posL + 1; 1);

          leftStart = posL + Length(leftSideTag)

        ];

        If(posL > 0 and posR > posL;

          Middle(text; leftStart; posR - leftStart);

          ""

        )

      )

        • 1. Re: Another custom function for text parsing
          weaverd

          Some further suggested refinements to account for the need to parse out text where the first and last required parsed items are not bound by a left side or right side tag:

           

          Let(

            [

              posL = Case(not IsEmpty(leftSideTag);Position(text; leftSideTag; 1; occurrence);1);

              posR = Case(not IsEmpty(rightSideTag); Position(text; rightSideTag; posL + 1; 1);Length(text)+1);

              leftStart = posL + Length(leftSideTag)

            ];

            If(posL > 0 and posR > posL;

              Middle(text; leftStart; posR - leftStart);

              ""

            )

          )

           

          For example in the previous CF, for a string of comma delimited values, the first value could not be parsed unless leftSideTag was a comma, and the last value could not be parsed unless the last character was a comma.

           

          e.g. ,A,B,C,D,E,

           

          In the above suggestion, if the leftSideTag is empty (""), the PosL will return 1, and if the rightSideTag is empty (""), PosL will return the length of the text +1, which will be the end of the line. Comma separated text such as A,B,C,D,E can now be parsed when the CF parameters are appropriately set.

           

           

          regards

          • 2. Re: Another custom function for text parsing
            David Moyer

            ah, excellent point.  Like many parsing routines, one often needs to bookend the text-in-question with something.  I use this in a list-parsing function, below.  Instead of commas, I needed line-feeds (¶)

            Custom Function:  ValueListIndex