Strip HTML using Lotus @Formula
Category TechnicalAfter I finished my LotusScript version, I decided to look into doing the same thing using the @Formula language. I did another check on Google, and found some code by Dave Mehan. I'm not going to rip on his code, because it is really good, but it doesn't really fit what I wanted to do.
Something I forgot to point out in my LotusScript posting is that it will conditionally strip out Orphan tags ("<" & ">"). I wanted this capability for the @Formula version as well, and you'll notice I am setting a variable (vStripOrphans) to @True in the code. (You could pull the value for this from a field, an ini value, or any other way your heart desires.)
So, I started by applying the same logic as my LotusScript version, and came up with the following. I have commented it pretty heavily, so it shouldn't need much explaining; however, you might notice that I have nested an @DoWhile inside an @Transform; which I think is pretty cool (pats self on back). You'll also notice I tend to break up my code into multiple lines -this is intentional and helps me to "see" the logic. Enjoy:
REM {Set the behavior};
vStripOrphans := @True;
REM {Use the @Text function in the event that the source field is Rich Text};
REM {This is NEW functionality for Release 6};
vCurrent := @Text(My_Source_Field_Name);
REM {Strip out all valid tags};
vCurrent := @Transform(vCurrent; "vElement";
@Do(
vTemp := vElement;
@DoWhile(
vTag := @Right(vTemp; "<");
vTag := @Left(vTag; ">");
vTemp := @If(vTag = ""; vTemp; @ReplaceSubstring(vTemp; "<" + vTag + ">"; ""));
vTag != ""
);
vElement := vTemp
)
);
REM {If not stripping out orphans, return the current value};
@If(vStripOrphans; ""; @Return(vCurrent));
REM {Strip out Orphans (< & >)};
vCurrent := @Transform(vCurrent; "vElement";
vElement := @ReplaceSubstring(vElement; "<":">"; "":"")
);
REM {now return tne current value};
vCurrent;
-Devin

The Pridelands
Chris Byrne
Show n' Tell Thursdays



Comments
Josh
Posted by Josh At 03:42:38 PM On 01/09/2012 | - Website - |