4 Replies Latest reply on Apr 8, 2014 5:02 AM by coherentkris

    ExplodeText Custom Function

    Hudi

      Hi,

       

      I need a little help fixing (or understanding) a custom function meant to explode text. I'm using the result of this function as the foreign key in a portal filter. Alternatively, if someone has a working function to accomplish this that would be ideal .

       

      It's two functions that I found on BrianDunning.com. The second one calls the first.

       

      1. ExplodedKey ( Text )

      If (

      Length ( Text ) > 1 ;

      ExplodedKey ( Left ( Text ; Length ( Text ) - 1 ) ) & "¶" & Text ;

      Text

      )

       

      2. ExplodedString( StringFieldName)

      Let(

      [FieldName = Left ( StringFieldName & " "; Position ( StringFieldName ; " "; 1 ; 1 ) - 1 );

      Counter = PatternCount ( StringFieldName ; " " )];

       

       

      Case(

      Counter = 0 ; "" ;

      Counter > 30 ; "ERROR: too many fields" ;

      ExplodedKey ( FieldName ) & "¶" &

      ExplodedKey (Substitute ( StringFieldName & " " ; FieldName & " " ; "" )

      )

      )

      )

       

       

      Here is the result I'm getting for "Son of Batman" and I can't figure out why.

       

      S

      So

      Son

      o

      of

      of

      of B

      of Ba

      of Bat

      of Batm

      of Batma

      of Batman

      of Batman

       

      "Son of Batman" looks like this when it should explode every word indivually, so user could type in "Batman" and the portal would include this record.

       

      THANK YOU

        • 1. Re: ExplodeText Custom Function
          coherentkris

          make sure the exploded key field is on the many side and the one side is a global text entry and it should work

          • 2. Re: ExplodeText Custom Function
            Mike_Mitchell

            Not sure about the function you got from Dunning's site, but this one should work:

             

            --------------------------------------------------------------------------------------------------------------------------------------

             

            /*

             

            Explodes a string as individual words. Example:

             

            inputString = "Hello world"

             

            output =

             

            H

            He

            Hel

            Hell

            Hello

            w

            wo

            wor

            worl

            world

             

            Parameters:

             

            inputString - string of characters to explode

            result - end result (initially empty)

             

            Needs cfExplodeText as a helper function

             

            Author: Mike Mitchell, Net Caster Solutions

            www.netcastersolutions.com

             

            */

             

            Let ( [

            resultToPass = Case ( not IsEmpty ( result ) ; result & "¶" ; "" ) ;

            inputAsValues = Substitute ( inputString ; " " ; "¶" ) ;

            inputValueCount = ValueCount ( inputAsValues ) ;

            curVal = GetValue ( inputAsValues ; 1 ) ;

            remainingVal = RightValues ( inputAsValues ; inputValueCount - 1 )

            ] ;

             

            Case (

            IsEmpty ( Substitute ( remainingVal ; "¶" ; "" )) ;

            resultToPass & cfExplodeText ( curVal ) ;

            cfExplodeStringAsWords ( remainingVal ; resultToPass & cfExplodeText ( curVal ))

            )

             

            )

             

            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------

             

            Mike

            • 3. Re: ExplodeText Custom Function
              Hudi

              Jackpot, Thank you.

               

              The necessary function that I used looks like this:

              cfExplodedText ( Text )


              If (

              Length ( Text ) > 1 ;

              ExplodedKey ( Left ( Text ; Length ( Text ) - 1 ) ) & "¶" & Text ;

              Text

              )

               

               

              It's called 'ExplodedKey' on BrianDunning.com but I used it and it works great.

               

              Many thanks

              • 4. Re: ExplodeText Custom Function
                coherentkris

                I think that was the exact CF i used in the file i posted.