3 Replies Latest reply on Oct 13, 2009 7:47 AM by mrvodka

    Text formatting with function help



      Text formatting with function help


      Hi All,


      My function skills are still at a relatively basic level, so I'm turning here for some help with a formatting function. What I need to do with it is pretty simple: Take a string of text and strip any non-letter or non-number characters (including spaces), and replace them with hyphens. After that I need to remove any instances of multiple hyphens in a row, leaving just one.


      Example: "Kickball -  Everything is a Miracle... Vinyl" becomes "Kickball-Everything-is-a-Miracle-Vinyl"


      Probably relatively simple thing, but I still don'thave my mind around functions within functions.



        • 1. Re: Text formatting with function help

          This could be done more elegantly with a custom function, but sometimes simple and ugly is easier to understand ;-)


          I've included a substitute for spaces and for periods then after that it cleans up multiple dashes together (up to 10).  To expand this just take this ["texttoremove"  ; "-"]; and replace the texttoremove with whatever you want to remove.  Just paste that in right where I have "PUT YOUR MODS HERE". 


          Substitute (
          txt ;
          [" " ; "-"];
          ["."; "-"];

          ["----------", "-"];
          ["---------", "-"] ;
          ["--------", "-"];
          ["-------", "-"];
          ["------", "-"];
          ["-----", "-"];
          ["----", "-"];
          ["---", "-"];
          ["--", "-"];
          ["-", "-"]

          • 2. Re: Text formatting with function help

            Oh, ok. That's easy enough. I didn't think to just include multiple dashes as substitute search strings.


            What would a custom function look like? I actually haven't gotten into them at all yet.



            • 3. Re: Text formatting with function help

              Try this calc:


              Let ( x = Filter ( YourField; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 " );
                           Substitute ( TrimAll ( x; 0; 0 ); " " ; "-" )





              *Edit: BTW, that is a space at the end after the zero.

                Edit: Typo fix.