Hi All,
Is there a way to use a script to reverse a 5 character string field on the Person record?
Example:
Pre-Script: ABCDE
Post-Script: EDCBA
I've been trying to adjust this script, but cannot identify which key to use.
Best,
Thomas
Solved! Go to Solution.
#set( $original = "ABCDE" )
#set( $reversed = "" )
#set( $codeUnits = $original.split("") )
#foreach( $i in [$math.sub($codeUnits.size(),1)..0] )
#set( $reversed = $reversed + $codeUnits[$i] )
#end
Thank you @SanfordWhiteman. This works beautifully.
Can I ask what the use case is for this? Seems pretty rare to get strings in reverse!
Also, must’ve saved my last post too quickly: thought I’d added the disclaimer that this doesn’t work with surrogate pairs nor with compound graphemes (combining marks, emoji complexions, etc.). In other words, as the variable name suggests, it works on 16-bit code units.
This is great information. I have not used Velocity script before, but am commenting so I can follow this topic for learning purposes in my growth and development! Thanks for sharing.