2 Replies Latest reply on Dec 2, 2016 10:04 AM by David Moyer

    Text Parsing by Pipe Character

    baldewicz

      Hi All,

       

      I am not the greatest at text parsing and I am a bit stumped on this most likely easy task.  I am trying to have an easy way to remember how the user navigated though a group of records so they maintain the ability to go back.  When a user is on the  Main Menu (MM) the Report::Position is automatically set to 1, once a user navigates to another record a pipe character is added and the selected records PK is appended to the list: 1|2.  I need to allow the user to navigate back though the list.

       

      For example I have a field which has a list of pipe delimitated numbers :  1|2|16|8

       

      I am able to return the second to last entry: 16

      Using:

      Let(

      ~values = Substitute(Report::Position; "|"; ¶);

      GetValue(~values;ValueCount(~values)-1)

      )

      I am able to get the count of the number of pipes:

      PatternCount ( Report::Position;"|" )

      But I also need to trim the list after grabbing the second to last entry

       

      What I am looking for is, and this very likely isn't the best way to do this:

       

      If (PatternCount(Report::Position;"|")<2;

       

      The list should revert to Main Menu (1) ;

      It should grab the second to last number and trim the last Pipe Characters off of the string )

       

       

      Example: Starting with 1|2 should grab the number 1 and set the  return 1 as the new list, where as starting with 1|2|16|8 should grab the number 16 and should return 1|2|16 as the new list.

       

      I hope this makes since.  Thank you all!

      Sandy

       

      Message was edited by: Sandra Baldewicz

        • 1. Re: Text Parsing by Pipe Character
          erolst

          You already have a list where the pipes are substituted - why not try

           

          Let ( [

            res = LeftValues ( ~values ; ValueCount ( ~values ) - 2 ) ;

            res = Left ( res ; Length ( res ) - 1 ) // LV adds a trailing return - get rid of it

            res = Substitute ( res ; ¶ ; "|" )

            ] ;

            res

          )

          1 of 1 people found this helpful
          • 2. Re: Text Parsing by Pipe Character
            David Moyer

            Hi,

            ... trim the last Pipe Characters off of the string

            just for that particular task, here's a model to look at:

            Let(

              [

                pipedList = Report::Position;

                lastPipe = Position ( pipedList; "|"; Length ( pipedList ); -1 )

              ];

              Left ( pipedList; lastPipe - 1 )

            )

            1 of 1 people found this helpful