Skip to main content
Level 1
Feb 22, 2022 10:02 PM UTC
Solved

Use velocity to reverse string field

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Feb 23, 2022 1:31 AM UTC
#set( $original = "ABCDE" ) #set( $reversed = "" ) #set( $codeUnits = $original.split("") ) #foreach( $i in [$math.sub($codeUnits.size(),1)..0] ) #set( $reversed = $reversed + $codeUnits[$i] ) #end

4 replies

SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Feb 23, 2022 1:31 AM UTC
#set( $original = "ABCDE" ) #set( $reversed = "" ) #set( $codeUnits = $original.split("") ) #foreach( $i in [$math.sub($codeUnits.size(),1)..0] ) #set( $reversed = $reversed + $codeUnits[$i] ) #end
Translate
trosen-cfAuthor
Level 1
Feb 23, 2022 5:55 PM UTC

Thank you @sanfordwhiteman. This works beautifully. 

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Feb 23, 2022 6:48 PM UTC

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.

Translate