3 Replies Latest reply on Oct 31, 2011 11:52 AM by philmodjunk

    conditional formatting of text between delimiter characters

    RolfNoyer

      Title

      conditional formatting of text between delimiter characters

      Post

      I want to write a calculation that will take a text, and give me the same text back but with any text appearing between delimiters { and } formatted in italics (later I can strip the delimiter characters).

      There may be multiple expressions between { and } in the source text so whatever the calculation is, it has to iterate through the text, i.e. not change just the first string between { and } and also must know to italicize only expressions between { and the very next following }.

      It seems like there should be an easy way to do this but I cannot figure it out.

      Using suggestions from an earlier forum post, I have this code ("Text" is a variable for the text name):

      Substitute
      ( Text ;
      Let ( [var 1 = Position ( Text ; "{" ; 1 ; 1 ) + 1 ;
             var 2 = Position ( Text ; "}" ; 1 ; 1 ) - var 1 ] ;
      Middle ( Text ; var 1 ; var 2 ) );
      TextStyleAdd (
      Let ( [var 1 = Position ( Text ; "{" ; 1 ; 1 ) + 1 ;
             var 2 = Position ( Texts ; "}" ; 1 ; 1 ) - var 1 ] ;
      Middle ( Text; var 1 ; var 2 ) ) ; Italic )
      )

      The problem is that it only italicizes the first string inside the delimiters, leaving the remaining ones untouched. How can I get this to iterate through the text?

      Thanks for any advice!

       

        • 1. Re: conditional formatting of text between delimiter characters
          philmodjunk

          You'll need a looping expression of one kind or another.

          In FileMaker Advanced, this can be done with a recursive custom function.

          In regular FileMaker you can use a looping script or a recursive calculation field.

          Which method would you like to try to implement?

          • 2. Re: conditional formatting of text between delimiter characters
            RolfNoyer

            Thanks for your response. I realized that I would need a recursive function but then could not write one because I don't have "Advanced" (although if it comes to that I might get that product).

            So a looping script or recursive calculation field would help me if you could point out how to do it.

            • 3. Re: conditional formatting of text between delimiter characters
              philmodjunk

              Set Variable [$text ; value: Yourtable::Text]
              Loop
                Exit Loop if [ Not Position ( $Text ; "{" ; 1 ; 1 ) // exit if there are no more delimitters remaining]
                Set Variable [$Text ; value: //Put a modified form your calc from your first post here]
              End Loop
              Set Field [YourTable::Text ; $text ]

              Change your calc to remove the delimitting text:

              Substitute
              ( Text ;
              Let ( [var 1 = Position ( $text; "{" ; 1 ; 1 )  ;
                     var 2 = Position ( $text; "}" ; 1 ; 1 ) - var 1 + 1 ] ;
              Middle ( $text; var 1 ; var 2 ) );
              TextStyleAdd (
              Let ( [var 1 = Position ( $text; "{" ; 1 ; 1 ) + 1 ;
                     var 2 = Position ( $text; "}" ; 1 ; 1 ) - var 1 ] ;
              Middle ( $text; var 1 ; var 2 ) ) ; Italic )
              )

              If I'm not off by one character position, that version should substitute Apple in place of {Apple}.