"scrub" Snippets

string scrubber

Delete all characters from string except characters that you define.
Created: 1462377050
View "string scrubber"
<mvt:comment>define your allowed characters</mvt:comment> <mvt:assign name="g.allowed" value="'abcdefghijklmnopqrstuvwxyz'" /> <mvt:comment>the string to scrub</mvt:comment> <mvt:assign name="g.string" value="'Test123-!hello'" /> <mvt:assign name="g.counter" value="1" /> <mvt:comment>for each letter in string</mvt:comment> <mvt:while expr="g.counter LE len(g.string)"> <mvt:comment>if this letter is contained in allowed, increment</mvt:comment> <mvt:if expr="substring(g.string, g.counter, 1) CIN g.allowed"> <mvt:assign name="g.counter" value="g.counter+1" /> <mvt:else> <mvt:comment>if letter is not in allowed, delete it, we don't need to increment because we just made the string 1 shorter</mvt:comment> <mvt:assign name="g.string" value="substring(g.string, 1, g.counter-1 ) $ substring(g.string, g.counter+1, (len(g.string)+1)-g.counter)" /> </mvt:if> </mvt:while> &mvt:global:string;