6 Replies Latest reply on Jun 23, 2013 10:43 AM by raybaudi

    Calc. (or script) To Replace UpperCase... crosspost

    alc

      I need a calc which would substitute Each capital letter in a Word with a space then that character...

       

      So:

      "ThisIsFourWords" would result in:

      "This Is Four Words"

       

      If neccessary, this could become a script... but either way, I'm stymied.

       

      I keep considering analysing each letter against ASCII numbers, but even then can't come up with a solution that wouldn't be both complex and tedious.

       

      Apologize to anyone else who also frequents the Filemaker Pro forums for crosspost... occured to me too late that this forum was more appropriate.

       

      Thanks in advance.

        • 1. Re: Calc. (or script) To Replace UpperCase... [crosspost]
          gcatnine
          You ca use comething like this:

          Set Variable [ $text; Value:"ThisIsFourWords"  ]
          Loop
          Set Variable [ $i; Value:$i + 1 ]
          Set Variable [ $char; Value:Middle ( $text; $i; 1) ]
          If [ Code ( $char) ≥ 65 and Code ( $char) ≤ 90 ]
               Set Variable [ $final_text; Value:$final_text & " " & $char ]
          Else
               Set Variable [ $final_text; Value:$final_text &  $char ]
          End If
          Exit Loop If [ $i = Length($text) ]
          End Loop

          where $text is your string (you can pass it as parameter) and $final_text is the modified string
          • 2. Re: Calc. (or script) To Replace UpperCase... [crosspost]
            raybaudi

            If yourTextField contains not more than 80 chars, you could try this calculation:

             

            TrimAll ( Char ( Substitute ( Code ( yourTextField )

            ; [ "00065" ; "0006500032" ]

            ; [ "00066" ; "0006600032" ]

            ; [ "00067" ; "0006700032" ]

            ; [ "00068" ; "0006800032" ]

            ; [ "00069" ; "0006900032" ]

            ; [ "00070" ; "0007000032" ]

            ; [ "00071" ; "0007100032" ]

            ; [ "00072" ; "0007200032" ]

            ; [ "00073" ; "0007300032" ]

            ; [ "00074" ; "0007400032" ]

            ; [ "00075" ; "0007500032" ]

            ; [ "00076" ; "0007600032" ]

            ; [ "00077" ; "0007700032" ]

            ; [ "00078" ; "0007800032" ]

            ; [ "00079" ; "0007900032" ]

            ; [ "00080" ; "0008000032" ]

            ; [ "00081" ; "0008100032" ]

            ; [ "00082" ; "0008200032" ]

            ; [ "00083" ; "0008300032" ]

            ; [ "00084" ; "0008400032" ]

            ; [ "00085" ; "0008500032" ]

            ; [ "00086" ; "0008600032" ]

            ; [ "00087" ; "0008700032" ]

            ; [ "00088" ; "0008800032" ]

            ; [ "00089" ; "0008900032" ]

            ; [ "00090" ; "0009000032" ]

            ) ) ; 1 ; 1 )

             

            If it could contain more chars, then it will be better to create a recursive custom function, something like:

             

            /*

            AddSpaceBeforeUpper ( text )

            */

             

            Let([

            Character = Left ( text ; 1 ) ;

            Space = If ( Length ( Filter ( Character ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ) ; " " )

            ];

            If ( Length ( text ) ; Space & Character & AddSpaceBeforeUpper ( Right ( text ; Length ( text ) - 1 ) ) )

            )

             

             

            to be trimmed in the calculation:

             

            TrimAll ( AddSpaceBeforeUpper ( YourTextField ) ; 1 ; 1 )

             

            Try it with YourTextField containing:

             

            MyBrainGoesToAnalysingEachLetterAgainstAsciiNumbers,ButEvenThenCan'tComeUpWithASolutionThatWouldBeBothComplexAndTedious

            • 3. Re: Calc. (or script) To Replace UpperCase... [crosspost]
              alc

              THANX, will give it a try

              • 4. Re: Calc. (or script) To Replace UpperCase... [crosspost]
                alc

                Egads- looks like you've done this before Daniele. And GiggleWorthyToBoot.

                Will have to reboot computer just to try.

                • 5. Re: Calc. (or script) To Replace UpperCase... [crosspost]
                  alc

                  Daniele,

                  Tried your first calc, worked like a charm.

                  NOW I need to comprehend (suppose it's as good a time as any, to curl up with some fine wine and read about code function.

                  the confusing part to me is that the substitution (what I would expect to be code for space char) is not always the same.

                   

                  Anyway, much thanks, saved me many hours of frustration.

                  • 6. Re: Calc. (or script) To Replace UpperCase... [crosspost]
                    raybaudi

                    alc ha scritto:

                     

                    the substitution (what I would expect to be code for space char) is not always the same.

                    But it is...00032 is the code for the space char.